FasterXML / jackson-annotations

Core annotations (annotations that only depend on jackson-core) for Jackson data processor
https://github.com/FasterXML/jackson
Apache License 2.0
1.03k stars 330 forks source link

@JsonIgnore does not work with booleans of type isSomething #165

Closed sergeol closed 4 years ago

sergeol commented 4 years ago

Sorry if I chose the wrong project, I'm not sure to understand what is where ...

Version information : I cannot find any fasterxml information in my pom, although I have some jackson libraries in maven dependancies (included in a package?):

    <groupId>com.fasterxml.jackson.module</groupId>
    <artifactId>jackson-modules-java8</artifactId>
    <version>2.9.8</version>

I develop a spring boot API, using the @JsonIgnore annotation to hide some fields in the API response;

I tried to ignore a boolean field named 'isSomething', but as the field is modified to 'something' in the response (I'm not sure what does that either), and @JsonIgnore is set on a field named 'isSomething', the field is not ignored => I get the boolean 'something' in my response.

So I changed my boolean name from 'isSomething' to 'something', and the @JsonIgnore worked.

Hope this helps.

cowtowncoder commented 4 years ago

Correct, field must be named something to match methods isSomething() or getSomething() (and setSomething()), otherwise it will not match (field is considered a property, getter/setter pair another one). Field names are ALWAYS assumed to just match property name: if not, add @JsonProperty("something") (or,@JsonIgnore`) on field.

In future, please use mailing list:

https://groups.google.com/forum/#!forum/jackson-user

or gitter chat

https://gitter.im/FasterXML/jackson-databind

for usage questions.