I have a simple POJO:
public class ADate {
private Integer day;
private Integer month;
private Integer year;
... // getters/setters/construct
I've found the some interesting code on Jackson github issues. Changed it a little and that's what I got:
public class ForceIntegerDeserializer extends JsonDeserializer {
@Override
public int deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
if (jsonParser.getCurrentToken() != JsonToken.VALUE_NUMBER_INT) {
throw deserializationContext.wrongTokenException(jsonParser, JsonToken.VALUE_STRING, "Attempted to parse String to int but this is forbidden");
}
return jsonParser.getValueAsInt();
}
}