hibernate/hibernate-orm · error · IllegalStateException

unexpected end of JSON [{}] in current processing state {}

Error message

unexpected end of JSON [{}] in current processing state {}

What it means

The parse loop in next() consumed separator tokens (',' or ':') and then ran out of input without producing an item — the document ends while the parser still expects more content. The message includes the last value window and current state, e.g. 'unexpected end of JSON [] in current processing state OBJECT'. It is the signature of JSON truncated right after a comma or colon.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/type/format/StringJsonDocumentReader.java:230

					}
					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() );
	}

	/**
	 * Gets the type of unquoted value.
	 * We assume that the String value follows JSON specification. I.e unquoted value that starts with 't' can't be anything else
	 * than <code>true</code>
	 * @param jsonValueChar the value
	 * @return the type of the value
	 */
	private JsonDocumentItemType getUnquotedValueType(char jsonValueChar) {
		switch(jsonValueChar) {
			case 't': {
				//true
				return JsonDocumentItemType.BOOLEAN_VALUE;
			}

View on GitHub (pinned to fad1729dce)

Solutions

  1. Repair the truncated value in the database so the document is complete
  2. Fix JSON-building code to never emit trailing ',' or ':' — use StringJoiner or a real serializer
  3. Validate completeness on write with a strict parser
  4. Catch IllegalStateException to skip/quarantine bad rows during load or migration

Example fix

// before: hand-built JSON with trailing separator
String json = "{";
for (Map.Entry<String,String> e : map.entrySet()) {
    json += "\"" + e.getKey() + "\":" + quote(e.getValue()) + ",";
}
json += "}"; // produces {"k":"v",}
// after: StringJoiner emits correct separators
String json = map.entrySet().stream()
        .map(e -> "\"" + e.getKey() + "\":" + quote(e.getValue()))
        .collect(java.util.stream.Collectors.joining(",", "{", "}"));
Defensive patterns

Strategy: try-catch

Validate before calling

// reject documents ending in a dangling separator before storing
static boolean endsClean(String json) {
    for (int i = json.length() - 1; i >= 0; i--) {
        char c = json.charAt(i);
        if (Character.isWhitespace(c)) continue;
        return c != ',' && c != ':';
    }
    return true;
}

Try / catch

try {
    entity = session.find(MyEntity.class, id);
} catch (IllegalStateException e) {
    if (e.getMessage() != null && e.getMessage().startsWith("unexpected end of JSON")) {
        throw new DataQualityException("JSON column truncated after separator", e);
    }
    throw e;
}

Prevention

When it happens

Trigger: Documents ending with a dangling separator: {"a": (ends right after the colon), {"a":1, (ends after the comma), [1,2, — the loop consumes SEPARATOR/KEY_VALUE_SEPARATOR via break, hasNext() then fails, and control falls out of the while loop to this throw.

Common situations: Truncated column values (too-narrow VARCHAR, cut transfers, partial writes); hand-built JSON strings that append ',' after the last element; manual editing that deleted the tail of the value.

Understand the failure class

Related errors


AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22). Data as JSON: /api/errors/832864d079362afe. Report an issue: GitHub.