Question
What is the proper way to customize deserialization process for JsonNullable of particular type
I want to customize JsonNullable<Boolean>
deserialization process. So I've found the class JsonNullableDeserializer :
I've implemented my own deserializer:
public class MyJsonNullableDeserializer extends JsonNullableDeserializer {
private static final long serialVersionUID = 1L;
private boolean isBooleanDeserializer = false;
public JsonNullableDeserializer(JavaType fullType, ValueInstantiator inst,
TypeDeserializer typeDeser, JsonDeserializer<?> deser) {
....
}
}
@Override
public JsonNullable<Object> deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
JsonToken t = p.getCurrentToken();
if (t == JsonToken.VALUE_STRING && isBooleanDeserializer && p.getText().trim().isEmpty() ) {
throw new IllegaArgumentException("....");
}
return super.deserialize(p, ctxt);
}
Now I want to register MyJsonNullableDeserializer
and I don't know how.
I see the class JsonNullableDeserializers
public class JsonNullableDeserializers extends Deserializers.Base {
@Override
public JsonDeserializer<?> findReferenceDeserializer(ReferenceType refType,
DeserializationConfig config, BeanDescription beanDesc,
TypeDeserializer contentTypeDeserializer, JsonDeserializer<?> contentDeserializer) {
return (refType.hasRawClass(JsonNullable.class)) ? new JsonNullableDeserializer(refType, null, contentTypeDeserializer,contentDeserializer) : null;
}
}
Looks like I have to replace
JsonNullableDeserializer
with MyJsonNullableDeserializer
somehow
I have no idea how to replace it. Could you please help ?
2 117
2