-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

文字列と数値の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 に答える