question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ObjectMapperSupplier implementation never loaded

See original GitHub issue

Summary A custom ObjectMapperSupplier implementation is not loaded on startup.

Steps to reproduce

  1. Create a custom ObjectMapperSupplier implementation that enables serialization features
  2. Register the implementation with the hibernate.types.jackson.object.mapper setting in your application.yml file
  3. 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:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
martinwithaarcommented, Oct 19, 2018

I can verify that moving the setting hibernate.types.jackson.object.mapper to a separate hibernate.properties file fixes my issue but it’s strange that it’s the only hibernate property that can’t be read from a Spring application.yml.

0reactions
vladmihalceacommented, May 25, 2021

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found