ObjectMapperSupplier implementation never loaded
See original GitHub issueSummary
A custom ObjectMapperSupplier
implementation is not loaded on startup.
Steps to reproduce
- Create a custom
ObjectMapperSupplier
implementation that enables serialization features - Register the implementation with the
hibernate.types.jackson.object.mapper
setting in yourapplication.yml
file - Run the application
Expected results The enabled serialization features are honored when retrieving json types from the database.
Actual results The enabled serialization features are not honored when retrieving json types from the database.
More info
When I add a throw new RuntimeException();
in the implementation’s get()
method it fails to throw on startup so I know the body is never run.
My application.yml
is as follows:
spring:
profiles:
active: dev
rabbitmq:
listener:
simple:
concurrency: 32
max-concurrency: 48
prefetch: 16
acknowledge-mode: auto
default-requeue-rejected: true
retry:
enabled: true
multiplier: 2
max-attempts: 10
stateless: true
initial-interval: 1s
max-interval: 30s
jpa:
database-platform: org.hibernate.dialect.MySQLDialect
hibernate:
ddl-auto: none
naming:
implicit-strategy: org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
properties:
hibernate.generate_statistics: false
hibernate.cache.use_query_cache: true
hibernate.cache.use_second_level_cache: false
hibernate.cache.region.factory_class: org.hibernate.cache.ehcache.EhCacheRegionFactory
hibernate.types.jackson.object.mapper: net.zuluconnect.ZuluconnectObjectMapperSupplier
hibernate.jdbc.batch_size: 20
hibernate.jdbc.batch_versioned_data: true
hibernate.order_inserts: true
hibernate.order_updates: true
datasource:
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: org.mariadb.jdbc.Driver
hikari:
minimum-idle: 32
maximum-pool-size: 48
idle-timeout: 60000
A separate profile-based configuration application-dev.yml
is also loaded:
spring:
rabbitmq:
host: "0.0.0.0"
username: guest
password: guest
datasource:
url: jdbc:mariadb://localhost:3306/my_db
hikari:
username: root
password:
logging:
level:
org: DEBUG
And my ObjectMapperSupplier
implementation:
package net.zuluconnect;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.vladmihalcea.hibernate.type.util.ObjectMapperSupplier;
@SuppressWarnings("unused")
public class ZuluconnectObjectMapperSupplier implements ObjectMapperSupplier {
@Override
public ObjectMapper get() {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true);
objectMapper.configure(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT, true);
objectMapper.configure(DeserializationFeature.USE_LONG_FOR_INTS, true);
return objectMapper;
}
}
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:13 (8 by maintainers)
Top Results From Across the Web
Use Jackson Objectmapper configured by Spring boot in ...
A BeanFactoryPostProcessor ensures that this bean is initialized before Hibernate (types) tries to load / get the ObjectMapper.
Read more >How to customize the Jackson ObjectMapper used by ...
Learn how to customize the Jackson ObjectMapper used for serializing and deserializing JSON objects to JSON column types when using the ...
Read more >OpenAPI 3 Library for spring-boot
Pre-loading setting to load OpenAPI on application startup. ... Never use this parameter in your production environment.
Read more >hibernate-types from vladmihalcea - GithubHelp
ObjectMapperSupplier implementation never loaded. Summary A custom ObjectMapperSupplier implementation is not loaded on startup. Steps to reproduce.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I can verify that moving the setting
hibernate.types.jackson.object.mapper
to a separatehibernate.properties
file fixes my issue but it’s strange that it’s the only hibernate property that can’t be read from a Springapplication.yml
.@Davio The change in HHH-13103 can only be used from Hibernate 5.5 onwards since it introduces a new class that will throw a
NoClassDefFoundError
on other Hibernate versions.So, if the HHH-14020 issue will be fixed, then Hibernate Types could use this feature for older Hibernate versions too. In the meanwhile, there is nothing to be done.