Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Jackson not recognizing 'is' Fields unless annoated with @JsonProperty

I have discovered the following problem whenever I have an "is" field in my JSON String Jackson doesn’t detect it without the additional @JsonProperty Tag. Before reporting this as a Bug, I wanted to make sure this is not caused by me. The UnmappedPropertyHandler interface is just a method with an @JsonAnySetter to report any unknown fields, which it does for the "is" Fields whenever they are not annotated with @JsonProperty and their name between the ( ).

public class Event implements UnmappedPropertyHandler {

    private boolean expired, isCommunity, isPersonal, active;

    public boolean isExpired() {
        return expired;
    }

    public boolean isCommunity() {
        return isCommunity;
    }

    public boolean isPersonal() {
        return isPersonal;
    }

    public boolean isActive() {
        return active;
    }

Snippet of the JSON String I’m parsing.

{
  "id": "5c7cb0d00000000000000000",
  "activation": "2022-06-01T16:00:00.000Z",
  "startString": "-11d 17h 33m 47s",
  ....
  "isPersonal": true,
  "isCommunity": true,
  ....
}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Jackson apparently scans the class that you pass in for getters and setters
and then use those methods for serialization and deserialization.

"Get", "Set", "is" are eliminated and what remains in those methods will be used as Json field.

Hence your "isCommunity" is changed into "community" and so on.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading