Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make JSON payload fields case insensitive when mapping to Java Object in REST API developed using SpringBoot

I am working on REST API developed using SpringBoot application. Here I want to make the fields in the payload(JSON) as case insensitive when mapping to a Java Object. Below is my code.

Payload {"limit":1,"name":"MATTHEW PHILLIPS"}

Request Object

private String limit;
private String name;

public String getLimit() {
      return limit;
    }

    public void setLimit(String limit) {
        this.limit = limit;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

I map the JSON payload to java Object directly using @RequestBody Spring annotation. My question here is How do I make the java Object to map to the fields ignoring the case.

Regards, Rakesh

like image 677
Rakesh Gourineni Avatar asked Jun 18 '15 20:06

Rakesh Gourineni


1 Answers

Well, if its Spring Boot application you can have this in your application.properties file: spring.jackson.mapper.accept_case_insensitive_properties=true

or if you use yaml:

spring:
  jackson:
    mapper:
      accept_case_insensitive_properties: true
like image 55
Vikas Prasad Avatar answered Sep 21 '22 14:09

Vikas Prasad