Deserialize case-insensitive JSON in Spring Boot Webclient


If you want to deserialize case-insensitive JSON in Spring Boot using Jackson, you can configure the ObjectMapper to use the ACCEPT_CASE_INSENSITIVE_PROPERTIES feature.

JSON

{
  "name": "Suresh",
  "EMAIL": "suresh@example.com",
  "phone": "123-456-7890"
}

Java Pojo

public class Person {
    private String name;
    private String email;
    private String phone;

//getter and setters and other methods
 }

WebClient

Example 1
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);

WebClient webClient = WebClient.builder()
        .exchangeStrategies(ExchangeStrategies.builder()
                .codecs(configurer -> configurer.defaultCodecs()
                        .jackson2JsonDecoder(new Jackson2JsonDecoder(objectMapper)))
                .build())
        .build();

Person person = webClient.get()
        .uri("https://example.com/api/person")
        .retrieve()
        .bodyToMono(Person.class)
        .block();

WebClient

Example 2
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);

WebClient webClient = WebClient.builder()
        .exchangeStrategies(ExchangeStrategies.builder()
                .codecs(configure ->
                                {
                                    Jackson2JsonDecoder decoder = new Jackson2JsonDecoder();
                                    decoder.getObjectMapper().configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
                                    configure.defaultCodecs().jackson2JsonDecoder(decoder);
                                }
                        )
                        .build())
        .build();
		
		
Person person = webClient.get()
        .uri("https://example.com/api/person")
        .retrieve()
        .bodyToMono(Person.class)
        .block();