Skip to content
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

EntityViewAwareMappingJackson2HttpMessageConverter doesn't use Spring Boot's ObjectMapper #1858

Closed
pvncoder opened this issue Jan 24, 2024 · 0 comments · Fixed by #1861
Closed

Comments

@pvncoder
Copy link
Contributor

pvncoder commented Jan 24, 2024

Description

See Zulip discussion here

The EntityViewAwareMappingJackson2HttpMessageConverter class, which is registered as a converter in the BlazePersistenceWebConfiguration class, does not use the ObjectMapper provided by the Spring Boot context. This results in the default ObjectMapper from the AbstractJackson2HttpMessageConverter class being used, which may not include any custom deserializers or other configuration that the user has applied, such as custom configuration with Jackson2ObjectMapperBuilder.

Expected behavior

The EntityViewAwareMappingJackson2HttpMessageConverter should use the ObjectMapper provided by the Spring Boot context. This would ensure that any custom configuration that the user has applied is used by Blaze Persistence.

Actual behavior

The EntityViewAwareMappingJackson2HttpMessageConverter uses the default ObjectMapper from the AbstractJackson2HttpMessageConverter class. This may result in incorrect deserialization if the custom ObjectMapper includes any custom deserializers or other configuration that is not present in the default ObjectMapper.

Steps to reproduce

  1. Download the zip file containing the test case (BlazePersistenceTestCaseCustomObjectMapperIssue.zip);
  2. Run the command ./mvnw clean install at the root of the project;
  3. Run the Spring Boot project with your IDE of choice or using the command java -jar target/blaze-persistence-test-case-custom-object-mapper-issue-0.0.1-SNAPSHOT.jar;
  4. Make a POST request to http://localhost:8080/users with the following body:
{
  "username": "random_username",
  "createdAt": "2024-01-24T12:00:00+03:00"
}

The error will occur. You can debug and notice that the LocalDateTimeCustomDeserializer is not called by the Blaze Persistence converter (even though it is registered in Spring Boot through the JacksonConfig class. You can check this in the UserController class by debugging the injected ObjectMapper object). If you send the request without the createdAt field, it will succeed normally.

Environment

Version: 1.6.11
Spring Boot: 3.2.2
JPA-Provider: Hibernate 6.4.1.Final
DBMS: h2, postgresql
Application Server: N/A

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