hibernate/hibernate-orm · error · UnsupportedOperationException
Unexpected JSON type " + type
Error message
Unexpected JSON type " + type
What it means
While reading the elements of a JSON array (deserializeArray), only VALUE, BOOLEAN_VALUE and OBJECT_START (nested json aggregate embeddables) are handled; every other item type falls to default and throws UnsupportedOperationException('Unexpected JSON type <type>'). In practice this means a structure the parser cannot represent - most notably nested arrays (ARRAY_START inside an array) - inside a JSON-mapped collection.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/type/descriptor/jdbc/JsonHelper.java:298
case NULL_VALUE:
arrayList.add( null );
break;
case NUMERIC_VALUE:
arrayList.add( adapter.fromNumericValue(jdbcJavaType, elementJdbcType ,reader, options) );
break;
case BOOLEAN_VALUE:
arrayList.add( reader.getBooleanValue() ? Boolean.TRUE : Boolean.FALSE );
break;
case VALUE:
arrayList.add( adapter.fromValue(jdbcJavaType, elementJdbcType ,reader, options) );
break;
case OBJECT_START:
assert elementJdbcType instanceof JsonJdbcType;
final EmbeddableMappingType embeddableMappingType = ((JsonJdbcType) elementJdbcType).getEmbeddableMappingType();
arrayList.add( consumeJsonDocumentItems(reader, embeddableMappingType, true, options) );
break;
default:
throw new UnsupportedOperationException( "Unexpected JSON type " + type );
}
}
throw new IllegalArgumentException( "Expected JSON array end, but none found." );
}
private static class CustomArrayList extends AbstractCollection<Object> implements Collection<Object> {
Object[] array = ArrayHelper.EMPTY_OBJECT_ARRAY;
int size;
public void ensureCapacity(int minCapacity) {
int oldCapacity = array.length;
if ( minCapacity > oldCapacity ) {
int newCapacity = oldCapacity + ( oldCapacity >> 1 );
newCapacity = Math.max( Math.max( newCapacity, minCapacity ), 10 );
array = Arrays.copyOf( array, newCapacity );
}View on GitHub (pinned to fad1729dce)
Solutions
- Avoid nested arrays in json aggregate data: model each element as an embeddable object (list of aggregate embeddables) instead of an array of arrays.
- Or flatten the structure to a single array and unpack positions in code.
Example fix
// before: stored [[1,2],[3,4]] mapped as
@JdbcTypeCode(SqlTypes.JSON) List<int[]> matrix; // parse -> Unexpected JSON type ARRAY_START
// after: store objects the parser understands
@JdbcTypeCode(SqlTypes.JSON) List<Row> matrix; // @Embeddable class Row { int x; int y; } Defensive patterns
Strategy: validation
Validate before calling
// Reject nested arrays before persisting (Jackson example)
static void assertNoNestedArrays(com.fasterxml.jackson.databind.JsonNode arrayNode) {
for (JsonNode element : arrayNode) {
if (element.isArray()) {
throw new IllegalArgumentException("Nested arrays are not supported by Hibernate JSON collection parsing");
}
}
} Try / catch
try {
return session.find(Product.class, id);
} catch (UnsupportedOperationException e) {
if (e.getMessage() != null && e.getMessage().startsWith("Unexpected JSON type")) {
// unsupported item structure inside a JSON array (e.g., nested array): remodel as objects
} else {
throw e;
}
} Prevention
- Model matrix-like data as a list of embeddable objects, not arrays of arrays
- Validate outgoing JSON structures in the JsonFormatMapper
- Test round-trips of complex JSON attributes before release
When it happens
Trigger: Loading a JSON array attribute whose elements are themselves arrays (e.g., [[1,2],[3,4]]); any item type outside the supported set inside an array bound to a plural JSON mapping.
Common situations: Domain data modeled as nested arrays (matrix-like values) stored in a column mapped as List<T>; other services writing richer JSON than the mapping supports.
Related errors
- Can't parse JSON array for selectable [%s] which is not of t
- Malformed JSON. Expected array but got: " + event
- Expected JSON array end, but none found.
- array case should be treated at upper level
- Duplicate collection definition '%s'
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/e676b487005afc12.
Report an issue: GitHub.