Hello,
I think there is an issue with the spring-boot-starter-web at v3.5.6.
I have this code :
@JsonProperty(value = "is_user_available")
private boolean isUserAvailable;
With spring boot v3.5.5, the API return as json :
{
"is_user_available": true
}
But after upgrading to spring boot v3.5.6, the API return as json :
{
"userAvailable" : true
}
Did I am the only one that have this issue ?
Thanks in advance, Regards,
BrandonFL
Comment From: wilkinsona
We've not aware of such a problem. 3.5.6 did not include a Jackson upgrade which perhaps would have been the most likely cause. If you would like us to spend some more time investigating, please spend some time providing a complete yet minimal sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.
Comment From: apscot
So apparently this is a problem because it is taking the name from the public getMethod of your class. if you write getAvailability()
then your json will have
{
"availability": true
}
it will remove get or is part and send that to your json.
@JsonProperty(value = "is_user_available")
you can set your property in the private variable.
and use jsonIgnore in the get method. it will show is_user_available
Comment From: brandonfl
Here is the reproduction repo :
https://github.com/brandonfl/spring-lombok-issue
With a simple DTO like this :
https://github.com/brandonfl/spring-lombok-issue/blob/f3a291bb9402c994567a963153a649d6e59fca7d/src/main/java/dev/brandonfl/bugtest/TestDTO.java#L10-L17
I get the result :
{
"test": {
"userAvailable": true,
"is_user_available": true
}
}
But before the update, I get :
{
"test": {
"is_user_available": true
}
}
Comment From: brandonfl
You can test by changing the Spring boot starter version on the repo at line 8 of the pom.xml
Spring boot starter v3.5.5 :
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.5.5</version>
<relativePath/>
</parent>
Result :
{
"test": {
"is_user_available": true
}
}
Spring boot starter v3.5.6 :
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.5.6</version>
<relativePath/>
</parent>
Result :
{
"test": {
"is_user_available": true,
"userAvailable": true
}
}
Comment From: wilkinsona
This is due to a change in Lombok 1.18.40. From its changelog:
IMPROBABLE BREAKING CHANGE: From versions 1.18.16 to 1.18.38, lombok automatically copies certain Jackson annotations (e.g.,
@JsonProperty
) from fields to the corresponding accessors (getters/setters). However, it turned out to be harmful in certain situations. Thus, Lombok does not automatically copy those annotations any more. You can restore the old behavior using the config keylombok.copyJacksonAnnotationsToAccessors = true
.
Comment From: Student4everandever
Repo for version 3.4.10 also!
Comment From: snicoll
Thanks for trying to help but the same answer applies.