REST Assured Jackson "JsonParseException" on the response body in CI
REST Assured used Jackson to deserialize the response body as JSON, but the body was not valid JSON. In CI this is usually an HTML error page, an empty body, or a proxy interstitial returned instead of the expected JSON.
What this error means
A test fails with "com.fasterxml.jackson.core.JsonParseException: Unexpected character ('<' (code 60))" when calling .as(), jsonPath(), or a JSON body matcher.
com.fasterxml.jackson.core.JsonParseException: Unexpected character ('<' (code 60)):
expected a valid value (JSON String, Number, Array, Object or token 'null', 'true' or 'false')
at [Source: (String)"<!DOCTYPE html>..."; line: 1, column: 2]Common causes
The response was HTML, not JSON
A 500 error page, a login redirect, or a gateway page returns HTML, so parsing the body as JSON fails on the first "<".
An empty or truncated body
A 204 No Content or a dropped connection returns nothing to parse, and Jackson raises a parse error.
How to fix it
Assert content type and log the body first
- Assert the response Content-Type is application/json before parsing.
- Log the body on failure to see what was actually returned.
- Fix the upstream cause (auth, error page) so real JSON comes back.
given().accept("application/json")
.when().get("/users/1")
.then().contentType("application/json").log().ifValidationFails();Handle the error response explicitly
If an endpoint can return HTML on error, assert the status first so you fail on the status, not on a confusing parse error.
How to prevent it
- Assert Content-Type before deserializing the body.
- Check status before parsing so error pages fail clearly.
- Ensure auth is configured so you do not receive login HTML.