I have an client api that use snake case naming strategy (custom ObjectMapper). Everything is set up properly and works great, but of course some things of SBA( version 2.3.1) UI doesn't work correctly(metrics, env...). I tried to implement InstanceExchangeFilterFunction to convert snake-case to camel-case for UI but without success. I would appreciated if someone could provide a sample of how to do that properly. If I understood it correctly I suppose to intercept client request, and to process it to camel case, and I don't know how to do that. Thanks
...
<parent>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.sba</groupId>
<artifactId>SpringBootAdmin</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>SpringBootAdmin</name>
<description>SpringBootAdmin</description>
<properties>
<java.version>1.8</java.version>
<spring-boot-admin.version>2.3.1</spring-boot-admin.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
...
@Import({SecurityConfig.class})
@Configuration
@EnableAdminServer
@SpringBootApplication
public class SpringBootAdminApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootAdminApplication.class, args);
}
}
@Configuration
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer {
@Bean
public InstanceExchangeFilterFunction caseStrategy(List<HttpMessageConverter<?>> converters) {
for(HttpMessageConverter<?> converter : converters) {
if(converter instanceof MappingJackson2HttpMessageConverter) {
MappingJackson2HttpMessageConverter jsonMessageConverter = (MappingJackson2HttpMessageConverter) converter;
ObjectMapper objectMapper = jsonMessageConverter.getObjectMapper();
((MappingJackson2HttpMessageConverter) converter).setObjectMapper(objectMapper);
}
}
return (instance, request, next) -> next.exchange(request);
}
}
I've also tried this piece of code and it resolves SBA UI but then front-end application doesn't work.
@Override
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
for (HttpMessageConverter<?> converter : converters) {
if (converter instanceof MappingJackson2HttpMessageConverter) {
MappingJackson2HttpMessageConverter jsonMessageConverter = (MappingJackson2HttpMessageConverter) converter;
ObjectMapper objectMapper = jsonMessageConverter.getObjectMapper();
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
}}
}
More or less, the following GitHub issue resolves this with the global JSON converter that is used for all endpoints and the actuator JSON converter for the actuator endpoints matched by the response
Content-Type
, e.g.,application/vnd.spring-boot.actuator.v3+json
. You specify both beans in the client application.https://github.com/codecentric/spring-boot-admin/issues/751#issuecomment-575999785
Note that after Spring Boot 2.5.0 the
ActuatorMediaType
is deprecated by theApiVersion
.