I have a json string like:
{
"name": "abc",
"type": "type1",
"artist": {
"name": "ally"
},
"other_part": "{"id":"ee50abd7","metadata":"..."}"
}
Like you see, "other_part" looks like in lenient format. It presents with quotation mark.
Here, I just want to convert it to a POJO class. But other_part gives parse error. Any suggestion.
POJO Class:
class Data
{
private String name;
private String type;
private Artist artist;
private Other other_part;
...getters
}
class Artist
{
private String name;
...getters
}
class Other
{
private String id;
private String metadata;
...getters
}
and restTemplate:
restTemplate.exchange(requestEntity, Data.class);
Error:
(although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value...
Thanks guys solved with JsonDeserialize:
public static class OtherConverter extends StdConverter<String, Other>
{
@Override
public Other convert(String value)
{
return new Gson().fromJson(value, Other.class);
}
}
class Data
{
private String name;
private String type;
private Artist artist;
@JsonDeserialize( converter = OtherConverter.class )
private Other other_part;
...getters
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…