Bandita Pradhan :
I am trying to create class
package com.spectrum.biller.orderdetails.model;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@ToString
public class TelephoneNumber {
private String number;
private String native;
private String preferred;
}
But I am getting error on variable native "syntax error on token, invalid variable declarator" . But, rest service is sending the Response with TelephoneNumber Class . Here is the response.
{
"telephoneNumber": {
"number": "string",
"native": "string",
"preferred": "string"
}
}
I need to know how I can declare the native keyword as variable in my class.
Thanks BPradhan
lugiorgi :
If you use jackson as json library you can annotate your fields with @JsonProperty. There you can define the key name that is mapped to your variable.
In your case you could do
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import com.fasterxml.jackson.annotation.JsonProperty;
@Getter
@Setter
@ToString
public class TelephoneNumber {
@JsonProperty("number")
private String number;
@JsonProperty("native")
private String nativeValue; //or however you want to name it
@JsonProperty("preferred")
private String preferred;
}
If you do not use jackson your used library probably has something similar.
Guess you like
Origin http://10.200.1.11:23101/article/api/json?id=417520&siteId=1