hibernate/hibernate-orm · error · IllegalArgumentException
Expected JSON object end, but none found.
Error message
Expected JSON object end, but none found.
What it means
JsonHelper.consumeJsonDocumentItems loops until the reader's OBJECT_END; if the reader is exhausted while still inside an object, it falls out of the loop and throws IllegalArgumentException('Expected JSON object end, but none found.') - the stored JSON is truncated or otherwise unterminated (missing '}').
Source
Thrown at hibernate-core/src/main/java/org/hibernate/type/descriptor/jdbc/JsonHelper.java:208
);
currentSelectableData = null;
}
case VALUE -> {
final JdbcMapping jdbcMapping = currentLevel.determineJdbcMapping( currentSelectableData );
currentLevel.addValue(
currentSelectableData,
adapter.fromValue(
jdbcMapping.getJdbcJavaType(),
jdbcMapping.getJdbcType(),
reader,
options
)
);
currentSelectableData = null;
}
}
}
throw new IllegalArgumentException( "Expected JSON object end, but none found." );
}
/**
* Deserialize a JSON value to Java Object
* @param embeddableMappingType the mapping type
* @param reader the JSON reader
* @param returnEmbeddable do we return an Embeddable object or array of Objects
* @param options wrappping options
* @return the deserialized value
*/
public static <X> X deserialize(
EmbeddableMappingType embeddableMappingType,
JsonDocumentReader reader,
boolean returnEmbeddable,
WrapperOptions options) throws SQLException {
final JsonDocumentItemType event;
if ( !reader.hasNext() || ( event = reader.next() ) == JsonDocumentItemType.NULL_VALUE ) {
return null;View on GitHub (pinned to fad1729dce)
Solutions
- Repair the affected rows (rewrite valid JSON) and find the writer that produced truncated documents.
- Enlarge the column (VARCHAR(n) bigger or use jsonb/json/TEXT types) so documents are never cut.
- Ensure all writes go through the Hibernate mapping / a validating JsonFormatMapper.
Example fix
-- before: column too short, writes truncated the document
ALTER TABLE product ALTER COLUMN attrs TYPE varchar(100); -- doc got cut
-- load fails: Expected JSON object end, but none found.
-- after: use a JSON-capable/longer column and repair rows
ALTER TABLE product ALTER COLUMN attrs TYPE jsonb;
UPDATE product SET attrs = '{}' WHERE NOT attrs::text LIKE '%}'; Defensive patterns
Strategy: validation
Validate before calling
// Before Hibernate reads it, confirm the column parses and closes its object
static void assertWellFormed(String json) {
try {
new org.json.JSONObject(json); // throws on truncated/unterminated objects
} catch (Exception e) {
throw new IllegalArgumentException("Broken JSON in column: " + json, e);
}
} Try / catch
try {
return session.find(Product.class, id);
} catch (IllegalArgumentException e) {
if (e.getMessage() != null && e.getMessage().startsWith("Expected JSON object end")) {
// truncated/unterminated object in the column: repair the row and enlarge the column
} else {
throw e;
}
} Prevention
- Use native JSON column types (jsonb/json) or generous lengths for JSON data
- Reject or log documents that fail strict parsing at write time
- Never hand-edit JSON columns; script migrations with validated JSON
When it happens
Trigger: Reading a JSON-mapped embeddable whose column value is a truncated/unterminated object: a column too short for the document, a writer that truncated the string, or a document broken by manual editing.
Common situations: VARCHAR columns whose length silently truncates JSON on write (strict mode off); migration scripts that cut strings; hand-edited rows; buggy custom serialization writing partial documents.
Related errors
- Malformed JSON. Expected object but got: " + event
- Expected JSON array end, but none found.
- Could not find selectable [%s] in embeddable type [%s] for J
- Can't parse JSON object for selectable [%s] which is not of
- Malformed JSON. Expected array but got: " + event
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/f33dd7dd5ba88beb.
Report an issue: GitHub.