Skip to content

How to get raw body of any response #415

Answered by ryber
aceton41k asked this question in Q&A
Discussion options

You must be logged in to vote

If it's a parsing error the original body is kept on the exception ... which, I realize is a little weird. but it's like this:

@Test
void ifTheObjectMapperFailsReturnEmptyAndAddToParsingError() {
HttpResponse<RequestCapture> request = Unirest.get(MockServer.INVALID_REQUEST)
.asObject(RequestCapture.class);
assertNull(request.getBody());
assertTrue(request.getParsingError().isPresent());
assertEquals("kong.unirest.UnirestException: com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'You': was expecting (JSON String, Number, Array, Obje…

Replies: 3 comments 4 replies

Comment options

You must be logged in to vote
3 replies
@aceton41k
Comment options

@ryber
Comment options

@aceton41k
Comment options

Answer selected by aceton41k
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@aceton41k
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants