Parse JSON tree to plain class using Jackson or its alternatives

后端 未结 2 1031
攒了一身酷
攒了一身酷 2021-01-21 00:31

How to parse that JSON:

{
    \"foo\": {
        \"bar\": {
            \"baz\": \"Hello\"
        },
        \"qux\": \"World\"
    }
}

Into t

2条回答
  •  情深已故
    2021-01-21 00:54

    I have found, that this feature is not implemented in Jackson yet, see issue.

    As a workaround, method below can be added into Foo class:

    @JsonProperty("foo")
    public void setFoo(JsonNode jsonNode) {
        this.qux = jsonNode.get("qux").getTextValue();
        this.baz = jsonNode.get("bar").get("baz").getTextValue();
    }
    

提交回复
热议问题