Reputation: 2012
I have json
like that:
{
"somethingElse": "foobar",
"snils": {
"number": "123"
}
}
And class:
@Data
public class Documents {
private String snilsNumber;
private String somethingElse;
}
Can I easily map json to my class with annotation or something else?
Upvotes: 1
Views: 375
Reputation: 38655
You can deserialise it using one extra update method with JsonProperty
annotation.
class Documents {
private String snilsNumber;
private String somethingElse;
@JsonProperty("snils")
private void unpackSnils(Map<String, Object> brand) {
this.snilsNumber = (String) brand.get("number");
}
// getters, setters, toString
}
See also:
Upvotes: 0
Reputation: 40048
You can use '@JsonRootName'
@Data
@JsonRootName(value = "snils")
@JsonIgnoreProperties(unknown = true)
public class Documents {
private String number;
}
Upvotes: 1