I have such case:
@Getter //lombook
@Bulider //lombook
@JsonDeserialize(builder = Person.PersonBuilder.class)
public class Person {
//...
@JsonDeserialize(using = RawJsonDeserializer.class)
private String someString;
@JsonPOJOBuilder
public static class PersonBuilder{
//...
}
}
My custom deserializer:
/**
* Deserializes from JSON object to string.
*/
public class RawJsonDeserializer extends JsonDeserializer<String> {
@Override
public String deserialize(JsonParser parser, DeserializationContext context) throws IOException,
JsonParseException {
ObjectMapper mapper = (ObjectMapper) parser.getCodec();
return mapper.writeValueAsString(mapper.readTree(parser));
}
}
Problem is ignoring RawJsonDeserializer deserializer. How to invoke it when i try get Person object from JSON? For example: From JSON ->
{
"someString": {
"key": "value"
}
}
To Person object where field someString is string ->
Assert.assertEquals("{\"key\": \"value\"},person.getSomeString());" \\ true
I am not familiar with Json serialization but looks like serialization it is conversion of dto into text representation. But in your example you use JsonDeserializer what is wrong. May be I am something misunderstood. Also you collect json object form text and again convert it into text what is confused me
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.