0

I have a json response looks like below

{
  “id”: 1,
  “name”: “Karen”,
  “phone”: “Samsung”
}

and a Java class like

public class Person {
    public int id;
    public Name name;
    public Phone phone;
}
private class Name {
    public String value;
}
private class Phone {
    public String brand;
}

As you will see that unlike normal way by defining the name and phone as String, currently they were defined as a class with only one field, and it is not able to change the structure. Is there any way to use some Json annotation on class level to map the Json value to be its property, something like @JsonProperty(Name.class, "value")?

Drex
  • 3,346
  • 9
  • 33
  • 58
  • Use custom deserializer! Here is exactly the same question :-) https://stackoverflow.com/questions/19158345/custom-json-deserialization-with-jackson – 30thh Oct 08 '21 at 06:30
  • Thank you, I know custom deserializer would work, just wondering any convenient way by using the JsonProperty or other magic annotation – Drex Oct 08 '21 at 06:58

0 Answers0