My server return results having 2 different types: SearchResultDTO when successefull and String when error. I need to handle these 2 types and return always SearchResultDTO type. Here is my deserializer:
public class SearchResultsDeserializer extends JsonDeserializer<SearchResultDTO> {
@Override
public SearchResultDTO deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
JsonToken t = jp.getCurrentToken();
if (t == JsonToken.VALUE_STRING){
return new SearchResultDTO(jp.getText());
} else {
return jp.readValueAs(SearchResultDTO.class);
}
}
}
When i run this code and server send SearchResultDTO object, jackson go in infinite loop by calling this function and returns with error: "java.lang.StackOverflowError: stack size 1036KB"