我有这种情况:
hard coded
我的自定义反序列化器:
@Getter //lombook
@Bulider //lombook
@JsonDeserialize(builder = Person.PersonBuilder.class)
public class Person {
//...
@JsonDeserialize(using = RawJsonDeserializer.class)
private String someString;
@JsonPOJOBuilder
public static class PersonBuilder{
//...
}
}
问题忽略了RawJsonDeserializer反序列化器。当我尝试从JSON获取Person对象时如何调用它? 例如: 从JSON->
/**
* 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));
}
}
到Person对象,其中字段 someString 是字符串->
{
"someString": {
"key": "value"
}
}