Skip to content

Poor jackson parsing error message in MappingJackson2HttpMessageConverter [SPR-11603] #16226

Closed
@spring-projects-issues

Description

@spring-projects-issues

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:

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions