I would like to create a Java Bean to do mapping with JSON object.
But the JSON object has an attribute name, public, which has conflict with Java, because public is an reserved word in Java. How to handle this problem?
How-to
You can utilize @JsonProperty to rename it.
The Java bean looks like (publicStr is mapping to public in JSON):
@Data @ToString public static class DsnDto { @JsonProperty("public") private String publicStr; private String secret; private String csp; }
Reference
[1] https://stackoverflow.com/questions/9741134/jackson-annotation-how-to-rename-element-names
No comments:
Post a Comment