我有一个 JSON 字符串,其中包含一个嵌套和包装的 JSON 字符串。我想用杰克逊反序列化它,但我不确定如何。这是一个示例 bean:
@JsonIgnoreProperties(ignoreUnknown = true)
public class SomePerson {
public final String ssn;
public final String birthday;
public final Address address;
@JsonCreator
public SomePerson(
@JsonProperty("ssn") String ssn,
@JsonProperty("birthday") String birthday,
@JsonProperty("data") Address address,
@JsonProperty("related") List<String> related) {
this.ssn = ssn;
this.birthday = birthday;
this.address = address;
}
@JsonIgnoreProperties(ignoreUnknown = true)
public static class Address {
public final String city;
public final String country;
@JsonCreator
public Address(
@JsonProperty("city") String city,
@JsonProperty("country") String country) {
this.city = city;
this.country = country;
}
}
}
JSON 字符串类似于:
{
ssn: "001",
birthday: "01.01.2020",
address: "{ city: \"London\", country: \"UK\" }"
}
虽然我之前已经反序列化了 nsted 对象 - 当对象是一个包裹的字符串时,我对如何做到这一点相当迷茫。