I'm using the latest Unirest, with the Jackson object mapper. I'm doing the following:
- POST, using
asObject(Response.class) to parse the response
- I'm also using
ifFailure(ErrorResponse.class, ...) to handle error responses
Expected:
- On 400+ error responses Unirest should use
ErrorResponse.class when trying to parse the response
Actual:
- It first tries to serialize the response to
Response.class
- If that fails, it uses the response body when trying to parse the
ErrorResponse.class
- HOWEVER, if the parsing of a Response.class is successful, Unirest tries to coerce the
Response.class to an ErrorResponse.class, and in my case, that leaves me with an empty ErrorResponse.class
We probably should go directly to using the error class on 400+ status codes.
It is also annoying that when using .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);, Jackson treats JSON which has completely different fields than my POJO as a successful de-serialization. I'd like to just instruct JSON to treat all my POJO properties as required by default, but that doesn't appear to be an option.
I'm using the latest Unirest, with the Jackson object mapper. I'm doing the following:
asObject(Response.class)to parse the responseifFailure(ErrorResponse.class, ...)to handle error responsesExpected:
ErrorResponse.classwhen trying to parse the responseActual:
Response.classErrorResponse.classResponse.classto anErrorResponse.class, and in my case, that leaves me with an emptyErrorResponse.classWe probably should go directly to using the error class on 400+ status codes.
It is also annoying that when using
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);, Jackson treats JSON which has completely different fields than my POJO as a successful de-serialization. I'd like to just instruct JSON to treat all my POJO properties as required by default, but that doesn't appear to be an option.