'JsonProperty in java
I found this question in other questions, but I think they are too old and they are not working anymore.
I'm consuming an external service that returns a JSON and I want to convert it into an object in my own service. At the same time, this object will be my service output.
My problem is using JsonProperty, I would like to rename some variables I'm receiving in my json, but it is not working, somehow it works in debugger, but not in the returned object.
import com.fasterxml.jackson.annotation.JsonProperty;
public class MyClass {
@JsonProperty("NAME")
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
So what I expect to receive is a json with a key name, but I get one with key NAME
// Expected:
{
"name": "John"
}
// Received
{
"NAME": "John"
}
As I can read in other solutions the problem is the import, some people are using old JsonProperty library, but I'm using the expecting one.
Is there anything else I should check to make it work?
Solution 1:[1]
So you are using an annotation making the response to have that "NAME" as a key. This is solely there to rename the JSON response keys. So removing it will let you get the key as "name"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Juliyanage Silva |