Jackson JSON – Rename Properties with @JsonProperty, @JsonSetter and @JsonGetter example

In this tutorial, we’re gonna look at ways to rename Properties of a Class using @JsonProperty, @JsonSetter and @JsonGetter.

I. Maven Dependency

II. @JsonProperty

@JsonProperty is used to indicate the property name in JSON. This annotation can be used on fields or getters or setters.

1. On Fields

Customer class:

App class for testing:

>> Result:

2. On Getters or Setters

Customer class:

App class for testing:

>> Result:

II. @JsonSetter and @JsonGetter

@JsonProperty is the new alternative to @JsonGetter and @JsonSetter. This example gives you the old approach:
Customer class:

App class for testing:

>> Result:

By JavaSampleApproach | February 6, 2018.


Related Posts


Got Something To Say:

Your email address will not be published. Required fields are marked *

*