When you have JSON containing a field (mapped as Date) which is set to the
empty string, e.g. {..., "myDateField":"", ...} the DefaultDateTypeAdapter
throws an JsonSyntaxException in the method "deserializeToDate" because an
emtpy string value can not be parsed by DateFormat.
Would it not make sense in the "deserialize" method to check for an emtpy
string before calling "deserializeToDate" and if an empty string is found to
return null?
public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
if (!(json instanceof JsonPrimitive)) {
throw new JsonParseException("The date should be a string value");
}
String value = json.getAsString();
if (value==null || "".equals(value)) {
return null;
}
Date date = deserializeToDate(json);
...
Original issue reported on code.google.com by ronald.p...@googlemail.com on 9 Oct 2012 at 9:42
Original issue reported on code.google.com by
ronald.p...@googlemail.com
on 9 Oct 2012 at 9:42