Spring-boot-admin: Allow snake case formatting

Created on 23 May 2018  路  7Comments  路  Source: codecentric/spring-boot-admin

A client application we have uses Jackson snake case formatting via the spring.jackson.property-naming-strategy: SNAKE_CASE.

When trying to view the environment tab for an instance, there is just a swirling loading gif even though I can see that instances//actuator/env/ is returning JSON data. You can also test this by adding the snake case property to the application settings for the admin server and observing that no applications show.

wontfix

Most helpful comment

In your piece of code, i can't see where you tell that Actuator endoints must be CAMEL_CASE?
I think that I miss understood what you are doing.
Could you help to make my application work in SNAKE_CASE and have all my actuators endpoints working with Spring Boot Admin? Thank you

All 7 comments

I think SBA should support the default format for actuator endpoints. It would be too tedious to support two formats in the UI.

When https://github.com/spring-projects/spring-boot/issues/12951 is resolved you could configure the objectMapper for the business components without affecting the actuator endpoint.

Until then one option (when using SBA 2.0) is to implement a InstanceExchangeFilterFunction which converts the snake-case to camel-case for the ui.

Or you don't reconfigure the global ObjectMapper in Spring Boot but add a HttpMessageConverter which uses snake case and is only active for your business endpoints. Examples for that can be found here: https://stackoverflow.com/questions/43079892

@joshiste

1.spring-projects/spring-boot#12951

just resolved health endpoint others are still not work with spring-boot 2.0

2.InstanceExchangeFilterFunction

Can you provide a sample

3.HttpMessageConverter

There are a lot of problems in this, We should modify every client

If you add this:

 @Bean
    public MappingJackson2HttpMessageConverter actuatorHttpMessageConverter() {
        MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(
            Jackson2ObjectMapperBuilder.json().featuresToDisable(WRITE_DATES_AS_TIMESTAMPS).build());
        converter.setSupportedMediaTypes(
            Collections.singletonList(MediaType.parseMediaType(ActuatorMediaType.V2_JSON)));
        return converter;
    }

to your client applications, the actuator endpoints are serialized not with the "global" object mapper and thus are not affected by the SNAKE_CASE naming.

I can't make it work. When I add your piece of code then my property-naming-strategy: SNAKE_CASE is ignored.
So all my WS returns JSON in CamelCase and this is not what I want. I want everything in SNAKE_CASE except /actuator in CAMEL_CASE to make SBA works

In your piece of code, i can't see where you tell that Actuator endoints must be CAMEL_CASE?
I think that I miss understood what you are doing.
Could you help to make my application work in SNAKE_CASE and have all my actuators endpoints working with Spring Boot Admin? Thank you

I just needed this myself. This is my approach to serialize the actuator endpoints using the "default" object mapper and everything else with a custom config.

```
@Bean
@Order(0)
public MappingJackson2HttpMessageConverter actuatorJacksonHttpMessageConverter(Jackson2ObjectMapperBuilder builder) {
var converter = new MappingJackson2HttpMessageConverter(builder.build()) {
@Override
protected boolean canWrite(MediaType mediaType) {
//only exact matches
if (mediaType == null) {
return false;
}
return super.canWrite(mediaType);
}
};
converter.setSupportedMediaTypes(MediaType.parseMediaTypes(List.of(
ActuatorMediaType.V1_JSON,
ActuatorMediaType.V2_JSON,
ActuatorMediaType.V3_JSON
)));
return converter;
}

@Bean
@Order(Ordered.LOWEST_PRECEDENCE)
MappingJackson2HttpMessageConverter defaultJackson2HttpMessageConverter(Jackson2ObjectMapperBuilder builder) {
    builder.serializationInclusion(JsonInclude.Include.NON_NULL).propertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
    return new MappingJackson2HttpMessageConverter(builder.build());
}

```

Was this page helpful?
0 / 5 - 0 ratings