-1

基于这段 json 需要什么 Jackson POJO 结构?

就像是 ?:

class POJO {

    private List<ToAddList> toAdd;
    private List<ToRemoveList> toRemove

}

class ToAddList(){
String name;
int pos;
}

class ToRemoveList(){
String name
}


///////////////////////JSON///////////////////////////
    {
        "toAdd": [
            {
                "name": "test",
                "pos": 0,
            },
            {
                "name": "test",
                "pos": 1,
            },
        ],
        "toRemove": [
            {
                "name": "test"
            },
            {
                "name": "test"
            }
        ]
    }
4

1 回答 1

2

你有一个简单的 bean,它有两个字段,一个字符串和一个数字。此 bean 用于列表中,列表包含在另一个 bean 中:

@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class SimpleBean implements Serializable {
    private String name;
    private Integer pos;

    // constructors, getters, setters
}

@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class RequestBean implements Serializable {
    private List<SimpleBean> toAdd;
    private List<SimpleBean> toRemove;

    // constructors, getters, setters
}

而已。

于 2012-05-23T15:43:40.150 回答