Reputation: 29
Can someone please let me know if below JSON to POJO conversion is possible or not,
Sample JSON
{
"city":"test",
"firstname":"nokia",
"lastname":"mobile"
}
Response Class
@Data
public class BRNResponse {
@JsonProperty("city")
public String city;
private Name name;
}
@Data
public class Name{
@JsonProperty("firstname")
public String firstName;
@JsonProperty("lastname")
public String lastName;
}
I am able to get city value but not the first name & last name, Please help me to sort out this
Upvotes: 1
Views: 54
Reputation:
Since you are using Jackson, try this:
ublic class BRNResponse {
@JsonProperty("city")
public String city;
// Unwrap the name and place its members directly into BRBResponse.
@JsonUnwrapped
private Name name;
}
See also https://www.baeldung.com/jackson-annotations
Upvotes: 2