How can Spring Boot use different Jackson serialized ObjectMappers for different controllers?
06:14 27 May 2026

Background: This is an older Spring Boot 2.4.5 project. A new module related to the intelligent agent API has been added.

We want to standardize the JSON format of the API returns for all controllers in the `com.xxx.controller.agent` directory, but without affecting the JSON return values ​​of older controllers.

class Data{ 
    private BigDecimal d = new BigDecimal("1.23000")
}
// agent controller return json
 => {d: '1.23'}
// old controller return json
 => {d: 1.23}

How can I achieve this?

spring spring-boot