0

I am struct in one of the scenarios and want the best solution. My problem statement is :

I want to call the same POST rest service /test/abc with payload

{
"emaid"="US12345" 
} 
or {
"emaId"="US12345" 
}

with a small change in variable name emaid as "I and i" small and caps case.

while trying with my approach I am getting exception as:

{"status_code": 2002, "status_message": "Unknown property emaId while deserializing XYZObject{firstName='asd', lastName='asds', email='asdsa@asd.com', mobile='526487', address1='qwewq', address2='wqwewqewq', city='San jose', emaid='null', emaidType='null'}", "timestamp": "2020-01-29T05:41:31Z" }

with the payload containing

{
.....
"emaId" : "US1234",                 --- I want both to work with single rest service please Explain
.....
}

as JSON.

Please help me. Thanks in advance.

Ashish Karn
  • 1,127
  • 1
  • 9
  • 20
  • Does this answer your question? [Case insensitive JSON to POJO mapping without changing the POJO](https://stackoverflow.com/questions/26058854/case-insensitive-json-to-pojo-mapping-without-changing-the-pojo) – Player_Neo Jan 29 '20 at 05:55
  • @BhanuHoysala This is the perfect answer what I was searching and this will work in my case as well. Thanks lots. Keep Up Good Work. :) – Ashish Karn Jan 29 '20 at 06:16

1 Answers1

0

In your controller mention both the parameters emailid and emailId and set both the parameters as optional parameters.

And manually check for your required parameter.

if(emailid !=null){
    // write your logic
}

if(emailId !=null){
    // write your logic
}

I hope this perfectly works for you!

Manikanta
  • 59
  • 1
  • 5