admin管理员组文章数量:1401673
Below is the JSON which I need to convert to Java Object.
{
"example": {
"rule_string": "Elected.Benefit Area~ ++~ Is Eq ual To~ ++~ \"MEDICAL\"~ And~ Ends with the Text~ (~ Elected.Benefit Plan Option~ ,~ \"PPO\"~ )~",
"rule_source": "Elected.Benefit Area~ Is Eq ual To~ \"MEDICAL\"~ ~And~ Ends with the Text~ (~ Elected.Benefit Plan Option~ ,~ \"PPO\"~~ )~ ~ ",
"rule_type": "if",
"ast": {
"data": "if_statement",
"children": [
{
"data": "and_test",
"children": [
{
"data": "concat",
"children": [
{
"data": "field",
"children": [
"Elected.Benefit Area"
],
"_meta": null
},
{
"data": "concat",
"children": [
{
"data": "field",
"children": [
"Is Eq ual To"
],
"_meta": null
},
{
"data": "string",
"children": [
"\"MEDICAL\""
],
"_meta": null
}
],
"_meta": null
}
],
"_meta": null
},
{
"data": "function",
"children": [
{
"data": "function_name",
"children": [
"Ends with the Text"
],
"_meta": null
},
{
"data": "function_args",
"children": [
{
"data": "field",
"children": [
"Elected.Benefit Plan Option"
],
"_meta": null
},
{
"data": "string",
"children": [
"\"PPO\""
],
"_meta": null
}
],
"_meta": null
}
],
"_meta": null
}
],
"_meta": null
}
],
"_meta": null
},
"valid": true,
"parse_error": null
}
}
I used / to generate the classes which are as below. I have removed setters & getters in the snippets below. Each of the setters & getters have the @JsonProperty annotation.
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
"rule_string",
"rule_source",
"rule_type",
"ast",
"valid",
"parse_error"
})
public class Example {
@JsonProperty("rule_string")
private String ruleString;
@JsonProperty("rule_source")
private String ruleSource;
@JsonProperty("rule_type")
private String ruleType;
@JsonProperty("ast")
private Ast ast;
@JsonProperty("valid")
private Boolean valid;
@JsonProperty("parse_error")
private Object parseError;
@JsonIgnore
private Map<String, Object> additionalProperties = new LinkedHashMap<String, Object>();
}
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
"data",
"children",
"_meta"
})
public class Ast {
@JsonProperty("data")
private String data;
@JsonProperty("children")
private List<Child> children;
@JsonProperty("_meta")
private Object meta;
@JsonIgnore
private Map<String, Object> additionalProperties = new LinkedHashMap<String, Object>();
}
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
"data",
"children",
"_meta"
})
public class Child {
@JsonProperty("data")
private String data;
@JsonProperty("children")
private List<Child__1> children;
@JsonProperty("_meta")
private Object meta;
@JsonIgnore
private Map<String, Object> additionalProperties = new LinkedHashMap<String, Object>();
}
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
"data",
"children",
"_meta"
})
public class Child__1 {
@JsonProperty("data")
private String data;
@JsonProperty("children")
private List<Child__2> children;
@JsonProperty("_meta")
private Object meta;
@JsonIgnore
private Map<String, Object> additionalProperties = new LinkedHashMap<String, Object>();
}
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
"data",
"children",
"_meta"
})
public class Child__2 {
@JsonProperty("data")
private String data;
@JsonProperty("children")
private List<String> children;
@JsonProperty("_meta")
private Object meta;
@JsonIgnore
private Map<String, Object> additionalProperties = new LinkedHashMap<String, Object>();
}
I suspect the issue lies in the inner most "chidren" node which is an array of Strings where as the other "children" nodes are arrays of objects. Will it be possible to parse this JSON into POJOs using Jackson?
本文标签: jacksonDeserializing heavily nested JSON to Java ObjectStack Overflow
版权声明:本文标题:jackson - Deserializing heavily nested JSON to Java Object - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744216579a2595665.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论