with Jackson, I'm trying to properly deserialize a JSON which contains empty string as no value values. Herein an example:
{
"code" : "REQ500",
"description" : "Problem with Service",
"params" : ""
}
and the bean I would get:
public final class MyError {
@JsonProperty("code")
private String code;
@JsonProperty("description")
private String description;
@JsonProperty("params")
private List<String> params;
// [CUT]
public void setParams(List<String> params) {
this.params = params;
}
}
Using ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, I've create an object mapper with
public static final ObjectMapper OBJECT_MAPPER = new ObjectMapper()
.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true)
.registerModule(new SimpleModule().addDeserializer(LocalDate.class, new DateDeserializer()));
expecting to have params = null
, but deserialization doesn't work. Herein the error I got:
com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot
deserialize instance of `java.util.ArrayList` out of VALUE_STRING token
at [Source: (String)"{
"code" : "REQ500",
"description" : "Problem with Service",
"params" : ""
}"; line: 4, column: 14] (through reference chain: solutions.infinitec.fabrick.models.common.MyError["params"])
at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:63)
Any hints on how to solve this issue? Am I wrong somewhere?
Thank you in advance for suggestions.