i have an class with the following annotations:
class A {
public Map<String,List<String>> references;
@JsonProperty
public Map<String,List<String>> getReferences() {
...
}
@JsonIgnore
public void setReferences(Map<String,List<String>>) {
}
...
}
}
What I try is to ignore the json on deserialization. But it doesn't work. Always when JSON String arrives the Jackson lib fill the references attribute. If I use only the @JsonIgnore annotation the getter doesn't work. Are there any solutions for this problem?
Thanks
@JsonIgnore annotation is used to ignore fields from de-serialization and serialization, it can be put directly on the instance member or on its getter or its setter.
@JsonIgnore is used at field level to mark a property or list of properties to be ignored.
@JsonIgnoreProperties. @JsonIgnoreProperties is a class-level annotation that marks a property or a list of properties that Jackson will ignore. Let's look at a quick example ignoring the property id from serialization: @JsonIgnoreProperties({ "id" }) public class BeanWithIgnore { public int id; public String name; }
The. @JsonIgnore. annotation marks a field in a POJO to be ignored by Jackson during serialization and deserialization. Jackson ignores the field in both JSON serialization and deserialization.
As of Jackson 2.6, there is a new and improved way to define read-only
and write-only
properties, using JsonProperty#access() annotation. This is recommended over use of separate JsonIgnore
and JsonProperty
annotations.
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
public Map<String,List<String>> references;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With