Combine JsonPath with Jackson's JsonProperty for nested nodes?

Viewed 245

I have the following JSON file (simplified, actually contains more fields, nested and unnested):

{
    "name": "Foo"
    "age":
    {
        "years": 29
        "months": 11
    }
}

And I have a Java POJO for the above, which only consists of Name, Years and Months. My question is, is there any way that we can combine JsonPath with Jackson's @JsonProperty annotation to fetch the nested fields without doing one of the more complicated approaches like this: https://www.baeldung.com/jackson-nested-values ? Something like

class Person
{
    @JsonProperty("$.name")
    String name;

    @JsonProperty("$.age.years")
    Integer years;

    @JsonProperty("$.age.months")
    Integer months;

    //Setters, getters
}

Thanks

0 Answers
Related