1
我想解析一个嵌套的json,其中父键包含两个不同的嵌套键对象(不是可以在列表中抽象和序列化的单个模型)。嵌套json的模型类
对于这个例子Json,什么是正确的Java模型(相应的类)?
{
"name" : "Jack",
"surname" : "Hopper",
"address" : "711-2880 Nulla St. Mankato Mississippi 96522",
"FatherKey" :
{
"ChildKeyNo1" :
{
"defaultKey" : "2_s_g",
"key1" : "4_s_g",
"key2" : "2_s_g"
},
"ChildKeyNo2" :
{
"defaultKey" : "4_s_g",
"key1" : "6_s_g",
"key2" : "7_s_g"
}
}
}
我想出:
public class MainJsonConfiguration{
private String name;
private String surname;
private String address;
private FatherKey fatherKey;
public MainJsonConfiguration(String name, String surname, String address, String fatherKey){
this.name = name;
this.surname = surname;
this.address = address;
this.fatherKey = new FatherKey(new ChildKey(), new ChildKey());
}
}
public class FatherKey{
private ChildKey childKey1;
private ChildKey childKey2;
public FatherKey(ChildKey childKey1, ChildKey childKey2){
this.childKey1 = childKey1;
this.childKey2 = childKey2;
}
}
public class ChildKey{
private String defaultKey;
private String key1;
private String key2;
public ChildKey(){
}
}
,但它的气味腥....
有什么建议?
非常感谢您
您可以使用FasterXML Jackson并轻松地将其解析为Map:https://github.com/FasterXML/jackson – duffymo