Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jersey/Jackson @JsonIgnore on setter

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

like image 282
guerilla Avatar asked Sep 26 '12 05:09

guerilla


People also ask

Where should I put JsonIgnore?

@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.

What is the use of @JsonIgnore annotation?

@JsonIgnore is used at field level to mark a property or list of properties to be ignored.

What is JsonIgnoreProperties?

@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; }

What is @JsonIgnore in spring boot?

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.


1 Answers

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;
like image 53
joakimbl Avatar answered Sep 27 '22 20:09

joakimbl