hibernate/hibernate-orm · error · IllegalStateException
unexpected read [{}] in current processing state {}
Error message
unexpected read [{}] in current processing state {} What it means
An unquoted token was consumed successfully, but the state machine is neither ARRAY nor OBJECT — bare literals are only legal as array elements or as an object attribute value after ':'. The message shows the token and state, e.g. 'unexpected read [a] in current processing state STARTING_OBJECT'. The two classic causes are unquoted object keys and top-level bare scalars.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/type/format/StringJsonDocumentReader.java:218
case SEPARATOR:
// unless we are processing an array, following SEPARATOR that will a key
break;
case OTHER:
// here we are in front of a boolean, a null or a numeric value.
// if none of these cases we're going to raise IllegalStateException
// put back what we've read
moveBufferPosition(-1);
final int valueSize = consumeNonStringValue();
if (valueSize == -1) {
throw new IllegalStateException( "Unrecognized marker: " + StringJsonDocumentMarker.markerOf(
this.jsonString.charAt( this.position )));
}
switch ( this.processingStates.getCurrent() ) {
case ARRAY:
case OBJECT:
return getUnquotedValueType(this.jsonString.charAt( this.jsonValueStart));
default:
throw new IllegalStateException( "unexpected read ["+
this.jsonString.substring( this.jsonValueStart,this.jsonValueEnd )+
"] in current processing state " +
this.processingStates.getCurrent() );
}
default: {
throw new IllegalStateException( "unexpected marker ["+
marker +
"] at position " + this.position );
}
}
}
throw new IllegalStateException( "unexpected end of JSON ["+
this.jsonString.substring( this.jsonValueStart,this.jsonValueEnd )+
"] in current processing state " +
this.processingStates.getCurrent() );
}
/**View on GitHub (pinned to fad1729dce)
Solutions
- Fix the stored document to strict JSON: quoted keys ({"a":1}) and object/array roots
- Make the producing system emit strict JSON (use a serializer, not string concatenation)
- Pre-validate on write with a strict parser
- Catch IllegalStateException around reads to identify and migrate offending rows
Example fix
-- before: unquoted key (JavaScript-style object literal)
UPDATE entity_table SET json_col = '{name:"Ada"}';
-- after: strict JSON
UPDATE entity_table SET json_col = '{"name":"Ada"}'; Defensive patterns
Strategy: validation
Validate before calling
static void assertStrictJsonObject(String candidate) {
com.fasterxml.jackson.databind.ObjectMapper m =
new com.fasterxml.jackson.databind.ObjectMapper()
.enable(com.fasterxml.jackson.core.JsonParser.Feature.STRICT_DUPLICATE_DETECTION);
try {
m.readTree(candidate);
} catch (Exception e) {
throw new IllegalArgumentException("Not strict JSON (unquoted keys? bare scalar root?): " + e.getMessage(), e);
}
} Try / catch
try {
entity = session.find(MyEntity.class, id);
} catch (IllegalStateException e) {
if (e.getMessage() != null && e.getMessage().startsWith("unexpected read [")) {
// stored document uses relaxed JSON (e.g. unquoted keys) - repair required
throw new DataQualityException("Column contains non-strict JSON", e);
}
throw e;
} Prevention
- Never build JSON with string concatenation; use a serializer
- Reject JavaScript-style literals (single quotes, unquoted keys) at the API boundary
- Wrap bare scalar values in an object or array before storing them in JSON columns
When it happens
Trigger: next() reading an OTHER token while state is STARTING_OBJECT (unquoted key like {a:1} — JSON requires keys in quotes), NONE (bare top-level scalar document like 42 or true), or OBJECT_KEY_NAME/ENDING_* states where a quoted key or structural token is required.
Common situations: Hand-written 'relaxed JSON' with unquoted keys or single quotes (JavaScript object literals) pasted into a column; systems emitting non-strict JSON; storing a plain number/string directly in a JSON column without wrapping it in an object or array.
Related errors
- unexpected quote read in current processing state {}
- Unexpected JsonProcessingState {}
- Unrecognized marker: {}
- unexpected end of JSON [{}] in current processing state {}
- Can't find ending quote of key name
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/37af84a3d103d984.
Report an issue: GitHub.