I am consuming a rest service where the incoming JSon Response is something like this
"thumbnailUrls": {
"small": "skinresources/unpackaged/images/default_event.jpg",
"medium": "skinresources/unpackaged/images/default_event.jpg",
"large": "skinresources/unpackaged/images/default_event.jpg",
"default": "skinresources/unpackaged/images/default_event.jpg"
},
I have created a Java Class to map the Values Listed below is the Java Code Below
public class ThumbNailUrlDTO {
private String small;
private String medium;
private String large;
private String default;
}
The issue that I am having is I can't use the default name here as it is java keyword how do I deal with this problem
yes "default", invalid VariableDeclaratorId, you can not use default as variable name in java , its a pre-define keyword in java.
change variable name & map like this for json field name:-
Use @JsonProperty :
public class ThumbNailUrlDTO {
@JsonProperty("small")
private String small;
@JsonProperty("medium")
private String medium;
@JsonProperty("large")
private String large;
@JsonProperty("default")
private String defaultStr;
}
This will solve the issue.
you can use annotation to custom JSON name used for a property like this:
public class ThumbNailUrlDTO {
private String small;
private String medium;
private String large;
@JsonProperty("default")
private String defaultVal;
}
In this way, you can avoid using java keyword "default".
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