Skip to content

Conversation

@TAKETODAY
Copy link
Contributor

This causes JacksonJsonHttpMessageConverter.read() 's contextClass to resolve to null

Determine why this fails with JacksonJsonHttpMessageConverter but passes with MappingJackson2HttpMessageConverter

Because the MappingJackson2HttpMessageConverter is a GenericHttpMessageConverter that explicitly provides the contextClass during reading, whereas the JacksonJsonHttpMessageConverter obtains it through (ResolvableType.getSource() as MethodParameter).getContainingClass.

T read(Type type, @Nullable Class<?> contextClass, HttpInputMessage inputMessage)
throws IOException, HttpMessageNotReadableException;

but type.getSource() is not instanceof MethodParameter

@Override
public Object read(ResolvableType type, HttpInputMessage inputMessage, @Nullable Map<String, Object> hints)
throws IOException, HttpMessageNotReadableException {
Class<?> contextClass = (type.getSource() instanceof MethodParameter parameter ? parameter.getContainingClass() : null);
JavaType javaType = getJavaType(type.getType(), contextClass);
return readJavaType(javaType, inputMessage, hints);
}

@Test
@Disabled("Determine why this fails with JacksonJsonHttpMessageConverter but passes with MappingJackson2HttpMessageConverter")
void resolveArgumentTypeVariable() throws Exception {
Method method = MySimpleParameterizedController.class.getMethod("handleDto", HttpEntity.class);
HandlerMethod handlerMethod = new HandlerMethod(new MySimpleParameterizedController(), method);
MethodParameter methodParam = handlerMethod.getMethodParameters()[0];
String content = "{\"name\" : \"Jad\"}";
this.servletRequest.setContent(content.getBytes(StandardCharsets.UTF_8));
this.servletRequest.setContentType(MediaType.APPLICATION_JSON_VALUE);
List<HttpMessageConverter<?>> converters = new ArrayList<>();
converters.add(new JacksonJsonHttpMessageConverter());
HttpEntityMethodProcessor processor = new HttpEntityMethodProcessor(converters);
@SuppressWarnings("unchecked")
HttpEntity<SimpleBean> result = (HttpEntity<SimpleBean>)
processor.resolveArgument(methodParam, mavContainer, webRequest, binderFactory);
assertThat(result).isNotNull();
assertThat(result.getBody().getName()).isEqualTo("Jad");
}

TAKETODAY referenced this pull request Jan 7, 2026
- Improve Javadoc.

- Suppress warnings for "removal".

- Update copyright headers.

- Migrate several tests from:
  - MappingJackson2MessageConverter to JacksonJsonMessageConverter
  - Jackson2JsonEncoder to JacksonJsonEncoder
  - Jackson2JsonDecoder to JacksonJsonDecoder
  - Jackson2SmileEncoder to JacksonSmileEncoder
  - Jackson2ObjectMapperBuilder to JsonMapper and XmlMapper
  - MappingJackson2JsonView to JacksonJsonView
  - MappingJackson2HttpMessageConverter to JacksonJsonHttpMessageConverter
  - MappingJackson2XmlHttpMessageConverter to JacksonXmlHttpMessageConverter
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jan 7, 2026
@bclozel
Copy link
Member

bclozel commented Jan 7, 2026

@TAKETODAY please sign your commit; no need to close/create a new PR, you can do this with:

git amend -s
git push --force

See this blog post for more information

@TAKETODAY TAKETODAY changed the title ResolvableType.getGenerics typeProvider was missing ResolvableType.getNested typeProvider was missing Jan 7, 2026
TAKETODAY and others added 5 commits January 7, 2026 18:07
…g, causing JacksonJsonHttpMessageConverter's contextClass to resolve to null

Signed-off-by: 海子 Yang <i.take.today@gmail.com>
Closes spring-projectsgh-36105

Signed-off-by: 海子 Yang <i.take.today@gmail.com>
See spring-projectsgh-36105
See spring-projectsgh-36099

Signed-off-by: 海子 Yang <i.take.today@gmail.com>
…s missing, causing JacksonJsonHttpMessageConverter's contextClass to resolve to null"

This reverts commit 2c5ba24.

Signed-off-by: 海子 Yang <i.take.today@gmail.com>
… of the owner

This is a change to a core library, and it's a very cautious commit. Therefore, this commit reverses the previous getGenerics modification, as getGenerics has a significant impact scope.

Signed-off-by: 海子 Yang <i.take.today@gmail.com>
@sdeleuze
Copy link
Contributor

sdeleuze commented Jan 8, 2026

Thanks for this PR, we are going to fix this but I tend to think it will be better (less risk of regression due to the changes on utility methods, more robust) to handle that using SmartHttpMessageConverter hints. As a consequence, I will decline this PR and create a related issue that I will tentativaly fix for 7.0.3.

@sdeleuze sdeleuze closed this Jan 8, 2026
@sdeleuze sdeleuze added in: web Issues in web modules (web, webmvc, webflux, websocket) status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jan 8, 2026
@TAKETODAY
Copy link
Contributor Author

Thanks for this PR, we are going to fix this but I tend to think it will be better (less risk of regression due to the changes on utility methods, more robust) to handle that using SmartHttpMessageConverter hints. As a consequence, I will decline this PR and create a related issue that I will tentativaly fix for 7.0.3.

OK,Thank you for your reply.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in: web Issues in web modules (web, webmvc, webflux, websocket) status: declined A suggestion or change that we don't feel we should currently apply

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants