I have custom StdDeserializer<Date>, how can i unit test the overridden deserialize method here?
or how can i prepare or mock JsonParser here for unit testing desterilize method?
public class StringToDateDeserializer extends StdDeserializer<Date> {
protected StdDateFormat df = new StdDateFormat();
public StringToDateDeserializer() {
this(null);
}
protected StringToDateDeserializer(Class<?> T) {
super(T);
}
@Override
public Date deserialize(JsonParser jsonParser, DeserializationContext ctxt) throws IOException {
String dateStr = jsonParser.getText();
if (StringUtils.isEmpty(dateStr)) {
return null;
}
try {
return df.parse(dateStr);
} catch (ParseException e) {
throw new MyCustomException("Invalid date passed, ISO 8601 is expected");
}
}
}