I want to check for valid Integer's when deserializing with GSON and report errors to an resultList object.
So I have this (register the Integer type) to GsonBuilder:
gson.registerTypeAdapter(Integer.class, new IntegerDeserializer(resultList));
And the IntegerDeserializer looks like
@Override
public Integer deserialize(JsonElement element, Type arg1, JsonDeserializationContext context) throws JsonParseException {
String integer = element.getAsString();
try {
Integer value = Integer.valueOf(integer);
return value;
} catch (NumberFormatException e) {
resultList.addError("?? fieldname ?? ", "Invalid number");
return null;
}
}
Is there a way to get the field name of the current Integer that is parsed? If this works I can use this as a generic way for checking json fields.