-2

I want to map below Json object with Java Pojo class ignoring parent class AuthToken.

{
  "AuthToken" : 
  {
    "id" : "1",
    "token" : "abcde1234xyz",
    "extendSession" : null
  } 
}

Pojo Class

public class TokenAccessResponseDTO {

    private String token;

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

}
Bhavesh Shah
  • 127
  • 2
  • 14
  • 1
    I would say use the JsonIgnoreProperties annotation and ignoreUnknown=true, then readValue() into a HashMap of – experiment unit 1998X Jan 10 '23 at 06:00
  • 2
    Though if you rather have a method to unpack the nested object directly without reading into hashmap, you could do so. Reference material [here](https://www.baeldung.com/jackson-nested-values) – experiment unit 1998X Jan 10 '23 at 06:05
  • 1
    Does this answer your question? [How can I deserialize it using Java?](https://stackoverflow.com/questions/69917981/how-can-i-deserialize-it-using-java) – Jim G. Jan 10 '23 at 15:58

1 Answers1

0

I solved this issue by mapping JSON Object to JsonNode and then adding the below syntax to fetch token

jsonNode.findValue("token").asText()

Bhavesh Shah
  • 127
  • 2
  • 14