Skip to content
Advertisement

How to Use @JsonProperty With Lombok?

Suppose we have a json response that we want to map it to our java class.

JavaScript

I had a data class that mapped access_token field in the json to accessToken field in the code. I used to use @JsonProperty annotation on getters and setters.

JavaScript

Then I decided to use Lombok annotations @Getter and @Setter. Since I do not have a getter and setter in my code, how can I map access_token field in the json to accessToken field in the code with Lombok annotations?

My code is like this right now and as you can expect, it cannot map the fields.

JavaScript

I do not want to name my variable to access_token because I also return access token as a json response and I want it to appear as accessToken in my json response.

Thank you.

Advertisement

Answer

Found a way to do it.

JavaScript

Another solution is to use @JsonAlias annotation.

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement