https://github.com/spring-projects/spring-framework/blob/d159cb65915840b2dc2297ee6b40309b8aa5d2aa/spring-web/src/main/java/org/springframework/http/converter/json/AbstractJackson2HttpMessageConverter.java#L267

In Branch 4.3.x, there is a null check for value. For whatever reason, 5.x doesn't have that check which results in a NullPointerException.

Comment From: rstoyanchev

That was removed as part of nullability checks f813712f5b413b354560cd7cc006352e9defa9a3 for 5.0 probably because it's not expected to be null.

MappingJacksonValue expects its value passed as a constructor arg to be non-null. That's indicated by the lack of @Nullable although it is true that internally that is not asserted. In the framework AbstractMappingJacksonResponseBodyAdvice avoids wrapping the value if it is null. Are you manually adding the wrapper?

Comment From: DanielArseneault

Yes in the project that I'm supporting, the Controllers are returning MappingJacksonValue type.

Comment From: rstoyanchev

I suppose we can re-introduce the null check as a defensive measure for the case of manual instantiation.

Comment From: rstoyanchev

On taking a closer look, with the NPE prevented, Jackson renders "null" which is unlikely what you want. As an alternative, the Jackson converter could skip rendering for null, but there are a number of other places where MappingJacksonValue is used some of which would be harder to change without changing contracts.

I think it would be better to add the missing notNull assertion to the MappingJacksonValue constructor and the controller would have to return null when the value is null. To help with the conditional wrapping, we could expose a method on MappingJacksonValue as follows:

@Nullable
public static MappingJacksonValue wrapIfNotNull(@Nullable Object value) {
    return (value != null ? new MappingJacksonValue(value) : null);
}

The controller would then be:

@GetMapping("/path")
public MappingJacksonValue handle(...) {
    Object value = ... ;
    return MappingJacksonValue.wrapIfNotNull(value);
}

Comment From: spring-projects-issues

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

Comment From: spring-projects-issues

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.