1

I have some troubles with parsing JSON using Jackson library

{
    "userName": "blablabla@gmail.com",
        "ID": {
            "uniqueID": "1234567"
        }
}

This is the part of the JSON, and my model is:

public class UserIdAndMail {
    @JsonProperty("uniqueID")
    private String id;

    
    @JsonProperty("userName")
    private String mail;

    public UserIdAndMail(String id, String mail) {
        this.id = id;
        this.mail = mail;
    }

    public UserIdAndMail() {}

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getMail() {
        return mail;
    }

    public void setMail(String mail) {
        this.mail = mail;
    }
}

'uniqueID' becomes null value when I try to parse the JSON to object. I have no idea how to get this field without creating an additional class "ID". Can there be a simpler solution to this task?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197

1 Answers1

1

Possible duplicate of - How to map a nested value to a property using Jackson annotations?

String id;

@JsonProperty("ID")
private void unpackNameFromNestedObject(Map<String, String> id) {
    this.id= id.get("uniqueID");
}
Jaydip Rakholiya
  • 792
  • 10
  • 20