2

I am having an issue with this Spring Boot customizer for Jackson. Debugging it appears to be configured, but Jackson is not using the model during (de)serialization.

import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.stereotype.Component;
import org.zalando.jackson.datatype.money.MoneyModule;


@Component
public class JacksonMoneyDatatypeCustomizer implements Jackson2ObjectMapperBuilderCustomizer {

    @Override
    public void customize(Jackson2ObjectMapperBuilder jacksonObjectMapperBuilder) {
        jacksonObjectMapperBuilder.modulesToInstall(new MoneyModule());
    }
}

Is this the correct way to solve this?

Chuck C
  • 423
  • 1
  • 4
  • 12
  • Also noticed that the JSR-310 stuff isn't working correctly either now. Any hints on the best way to debug how spring boot is applying these modules and using the resulting ObjectMapper? – Chuck C Jun 02 '17 at 14:55

1 Answers1

2

It's one of the methods to customize it.

For adding a module a more simple approach is to just define the module as a bean, it will then be picked up and added to the ObjectMapper

@Bean
public Module moneyModule(){
      return new MoneyModule();
}

https://docs.spring.io/spring-boot/docs/current/reference/html/howto-spring-mvc.html#howto-customize-the-jackson-objectmapper

More likely there's an issue with the implementation than the registering of the module itself.

Darren Forsythe
  • 10,712
  • 4
  • 43
  • 54