I have this POJO:
public class SetPoint {
private String tagName;
//more fields
//getters and setters
}
I'm getting SetPoints from a REST API, do something with them and then send them again. Problem is that I want deserialize a SetPoint from a JSON like:
{
"tagnameOpc" : "6GH783",
//more fields
}
But when I send them, I want serialize a SetPoint as:
{
"tagName" : "6GH783"
//more fields
}
I mean, I want the property tagName to be named different in each case.
Is this possible?
Try using a different JsonProperty annotation for the getter and the setter. E.g.
@JsonProperty("tagnameOpc")
void setTagName(String name)
@JsonProperty("tagName")
String getTagName()
If that doesn't work try with an extra setter
@JsonIgnore
void setTagName(String name)
@JsonProperty("tagnameOpc")
void setTagNameOpc(String name) {
setTagName(name);
}
@JsonProperty("tagName")
String getTagName()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With