jackson - Deserializing heavily nested JSON to Java Object - Stack Overflow

Below is the JSON which I need to convert to Java Object.{"example": {"rule_string"

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?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744216580a4563581.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信