1

次の POJO を指定します。

class A {
 private String name;
 private String desc;
 private List<A> subclasses;
}

サブクラスからフィールド desc` を除外することで、そのような json を生成します。

{
 name : "aname"
 desc: "adesc",
 subclasses : [{
      name : "aname"
 },{
      name : "anotherame"
 }]
}

または、子クラスではなく親クラスのフィールド

4

1 に答える 1

2

フィールドを除外するには、@JsonIgnore注釈を使用します。ここをもっと見てください -

http://forum.springsource.org/showthread.php?92684-Exclude-bean-field-from-JSON-response

そしてここ -

http://jackson.codehaus.org/1.0.0/javadoc/org/codehaus/jackson/annotate/JsonIgnore.html

于 2013-02-21T16:11:45.533 に答える