Reputation: 5168
This relates to this question but I want to deserialize rather than serialize
I receive a json object from the server..
One of the values in the json object can be either a string or a string array.
It is possible to get this to work by defining a Object and casting it like so.
@JsonProperty("integration/enabled-mime-types") public Object object;
List<String> list = (List<String>) object;
String string = (String) object;
However i would like to this as List rather than an object. The code I am using is this
@JsonDeserialize
@JsonProperty("integration/enabled-mime-types")
public void setMimeTypes(Object object) {
if(object instanceof List) {
this.mimeTypesArray = (ArrayList<String>) object;
} else {
this.mimeTypesArray.add((String) object);
}
}
But the List is never set. How to go about this?
Upvotes: 0
Views: 133
Reputation: 5168
The problem was that I had another setter for the array and annotated that with @JsonIgnore. That caused the objectmapper to ignore all setters and not only the only annotated
Upvotes: 1