-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Null coercion not working with property-based @JsonCreator
#2024
Comments
Looks like problem is that So. The place where this can be done is either in |
The exact same issue still occurs with Currently there is a workaround (source): private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper().registerModule(new SimpleModule().setDeserializerModifier(new NullCollectionsAsEmptyModifier()));
private static abstract class ContextualJsonDeserializer extends JsonDeserializer<Object> implements ContextualDeserializer { }
private static class NullCollectionsAsEmptyModifier extends BeanDeserializerModifier {
@Override
public JsonDeserializer<?> modifyMapDeserializer(DeserializationConfig config, MapType type, BeanDescription beanDesc, JsonDeserializer<?> deserializer) {
return new ContextualJsonDeserializer() {
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property) throws JsonMappingException {
return modifyMapDeserializer(config, type, beanDesc, ((ContextualDeserializer) deserializer).createContextual(ctxt, property));
}
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
return deserializer.deserialize(p, ctxt);
}
@Override
public Object getNullValue(DeserializationContext ctxt) {
return Collections.emptyMap();
}
};
}
@Override
public JsonDeserializer<?> modifyCollectionDeserializer(DeserializationConfig config, CollectionType type, BeanDescription beanDesc, JsonDeserializer<?> deserializer) {
return new ContextualJsonDeserializer() {
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property) throws JsonMappingException {
return modifyCollectionDeserializer(config, type, beanDesc, ((ContextualDeserializer) deserializer).createContextual(ctxt, property));
}
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
return deserializer.deserialize(p, ctxt);
}
@Override
public Object getNullValue(DeserializationContext ctxt) {
return Collections.emptyList();
}
};
}
} |
I just fixed #2458 and I think these two were actually the same issue -- so although this is older, I think I'll close this as duplicate due to release notes adding fixing of the other issue. |
(note: follow-up to #1402 for null coercion)
Although null coercion (and skipping, error reporting) works with fields, setters, it appears not to work as intended via Creator methods. Would be good if it did.
This occurs up to
2.9.5
.The text was updated successfully, but these errors were encountered: