i have an class with the following annotations:
class A {
public Map> references;
@JsonProperty
public Map
I think there are two key pieces that should enable you to have "read-only collections" as desired. First, in addition to ignoring the setter, ensure that your field is also marked with @JsonIgnore
:
class A {
@JsonIgnore
public Map> references;
@JsonProperty
public Map> getReferences() { ... }
@JsonIgnore
public void setReferences(Map>) { ... }
}
Second, in order to prevent the getters from being used as setters, disable the USE_GETTERS_AS_SETTERS
feature:
ObjectMapper mapper = new ObjectMapper();
mapper.disable(MapperFeature.USE_GETTERS_AS_SETTERS);