Closed
Description
Matteo Sumberaz opened SPR-11603 and commented
Hi all, while struggling with serialization bugs I've noticed that the debugging for SerializationContext.hasValueDeserializerFor
public boolean hasValueDeserializerFor(JavaType type, AtomicReference<Throwable> cause) {
try {
return _cache.hasValueDeserializerFor(this, _factory, type);
} catch (JsonMappingException e) {
if (cause != null) {
cause.set(e);
}
} catch (RuntimeException e) {
if (cause == null) { // earlier behavior
throw e;
}
cause.set(e);
}
return false;
}
is pretty bad if called by the ObjectMapper.canDeserialize method, that just pass null on the cause parameter
public boolean canDeserialize(JavaType type)
{
return createDeserializationContext(null,
getDeserializationConfig()).hasValueDeserializerFor(type, null);
}
and MappingJackson2HttpMessageConverter does exactly that
public boolean canRead(Type type, Class<?> contextClass, MediaType mediaType) {
JavaType javaType = getJavaType(type, contextClass);
return (this.objectMapper.canDeserialize(javaType) && canRead(mediaType));
}
It is possible to improve this bubbling in some way the exceptions from the canDeserialize method?
Affects: 4.0 GA
Issue Links:
- Log caught exception in MappingJackson2HttpMessageConverter [SPR-11403] #16030 Log caught exception in MappingJackson2HttpMessageConverter
- MappingJackson2(Http)MessageConverter should be more verbose in canRead/canWrite checks (on Jackson 2.3) [SPR-11261] #15886 MappingJackson2(Http)MessageConverter should be more verbose in canRead/canWrite checks (on Jackson 2.3)