question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@JSONProperty for a field 'is_deleted' is serialized as `_deleted`

See original GitHub issue

Hi, I am using Jackson 2.9.5. I have an Entity Structure Like this.

@Entity
@Data
public class PersonEntity {
 
      @JsonProperty("is_deleted")
      private boolean is_deleted;

}

On Deserialization, there are 2 fields.

{
   "_deleted" : "true",
   "is_deleted":"true"
}

Setting any 1 of the above from REST Client sets the value for the field is_deleted.

Suppose, I tweak my value a little bit and change my Entity as

@Entity
@Data
public class PersonEntity {
 
      @JsonProperty("is_deleted")
      private boolean isDeleted;

}

Again I get 2 fields on serialization,

{
   "deleted" : "true",
   "is_deleted":"true"
}

Setting any any 1 of the above from REST Client sets the value for the field isDeleted.

However, when I change this field without the is part,

@Entity
@Data
public class PersonEntity {
 
      @JsonProperty("is_deleted")
      private boolean deleted;

}

there is only 1 field that is correctly serialized as is_deleted.

I use Lombok for getters and setters. May I know the reason for this ambiguity? @cowtowncoder

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
WellingRcommented, Feb 7, 2020

Try adding

lombok.copyableAnnotations += com.fasterxml.jackson.annotation.JsonProperty

to your lombok.config file. This will ensure that the generated getters and setters will also receive the @JsonProperty annotation

0reactions
cowtowncodercommented, Feb 7, 2020

Thank you @WellingR !

I will close this issue as I do not see anything that can be done on Jackson side, but I hope this comment helps in working around such issue on Lombok side.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jackson renames primitive boolean field by removing 'is'
In JSON, the key is coming as {"success": true} . I want the key as isSuccess itself. Is Jackson using the setter method...
Read more >
JSON Serializer: Overviewing if Deleted is True - IntelliTect
Search for Serialization · Only select 'Id' and 'Deleted' from the database. · Pull all the data from the database, but set all...
Read more >
Serialization Attributes - Json.NET
JsonPropertyAttribute - Placed on fields and properties to control how they should be serialized as a property in a JSON object.
Read more >
Serialization Tutorial - GitHub Pages
A class map is a structure that defines the mapping between a class and a BSON document. It contains a list of the...
Read more >
How to get json response only with an id of the related entity
Fix the deserialization issue. To help deserialize the task object properly, add the @JsonProperty annotation and specify the json object field ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found