1

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);

            }}
    }
Sonny
  • 11
  • 3

1 Answers1

0

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 the ApiVersion.

CAPS LOCK
  • 1,960
  • 3
  • 26
  • 41
  • Thank you for your answer. I tried all of these but nothing seems to be working for me. Thank you anyway. – Sonny Sep 20 '21 at 06:38
  • I've had the very same issue with the Spring Boot Admin UI and the mentioned approach resolved it. – CAPS LOCK Sep 20 '21 at 07:34
  • Yes, it resolves SBA UI, but unfortunately then front-end application doesn't work like suppose to. – Sonny Sep 20 '21 at 08:20
  • Does your front-end app use the actuator endpoints? – CAPS LOCK Sep 20 '21 at 08:28
  • It don't use them. So your suggestion (https://github.com/codecentric/spring-boot-admin/issues/751#issuecomment-575999785) makes perfect sense, and I can't figured out why it's not working – Sonny Sep 20 '21 at 08:53