Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

JsonProperty when source and destination requires different variable names

I have a source A, a wrapper API B and a destination C.
I have to call wrapper API B from destination C. I have no access to source A.

source A produces following json output:

{
"id" : 1,
"created_on" : "27July"
}

In wrapper API B, I am consuming the above JSON output using following POJO:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

class B
{
Long id;
String created_on;
}

Wrapper API is able to get the value of created_on from source A. When I call A from B, I get this ouptut:

{
"id" : 1,
"created_on" : "27July"
}

But in destination C, i have the following POJO:

class C
{ 
Long id
String createdOn 
}

When I call Wrapper API B from C, i am not able to get the field ‘createdOn’.
When I call B from C, i get only this:

{
          "id" : 1
}

The mapping between created_on and createdOn is not happening.
Basically, i want to return ‘createdOn’ from Wrapper API B instead of ‘created_on’.
Currently, wrapper B is sending ‘created_on’ , but i want it to return ‘createdOn’.
How do I do it? I have tried @JSONProperty but it is not working

>Solution :

public class C { 
    Long id
    @JsonProperty("created_on")
    String createdOn 
}

It’s should works.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading