EntityViewAwareMappingJackson2HttpMessageConverter doesn't use Spring Boot's ObjectMapper #1858
Labels
component: entity-view
component: jackson
component: spring-data
component: spring-data-webflux
component: spring-data-webmvc
kind: bug
workaround available
worth: high
Implementing this has a high worth
Milestone
Description
See Zulip discussion here
The
EntityViewAwareMappingJackson2HttpMessageConverter
class, which is registered as a converter in theBlazePersistenceWebConfiguration
class, does not use theObjectMapper
provided by the Spring Boot context. This results in the defaultObjectMapper
from theAbstractJackson2HttpMessageConverter
class being used, which may not include any custom deserializers or other configuration that the user has applied, such as custom configuration withJackson2ObjectMapperBuilder
.Expected behavior
The
EntityViewAwareMappingJackson2HttpMessageConverter
should use theObjectMapper
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 defaultObjectMapper
from theAbstractJackson2HttpMessageConverter
class. This may result in incorrect deserialization if the customObjectMapper
includes any custom deserializers or other configuration that is not present in the defaultObjectMapper
.Steps to reproduce
./mvnw clean install
at the root of the project;java -jar target/blaze-persistence-test-case-custom-object-mapper-issue-0.0.1-SNAPSHOT.jar
;http://localhost:8080/users
with the following body: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 theJacksonConfig
class. You can check this in theUserController
class by debugging the injectedObjectMapper
object). If you send the request without thecreatedAt
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
The text was updated successfully, but these errors were encountered: