hibernate/hibernate-orm · error · IllegalArgumentException
Could not deserialize string to java type: {}
Error message
Could not deserialize string to java type: {} What it means
JacksonOsonFormatMapper is the JSON FormatMapper Hibernate uses for @JdbcTypeCode(SqlTypes.JSON) attributes on Oracle (Jackson ObjectMapper plus the Oracle OsonModule, see JacksonOsonFormatMapper.java:55-59). This IllegalArgumentException wraps a Jackson JsonProcessingException thrown when ObjectMapper.readValue fails to parse the stored column text into the attribute's Java type. The original Jackson message (malformed JSON, unknown field, no deserializer, wrong shape) is in the cause.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/type/format/jackson/JacksonOsonFormatMapper.java:89
}
@Override
public boolean supportsSourceType(Class<?> sourceType) {
return JsonParser.class.isAssignableFrom( sourceType );
}
@Override
public boolean supportsTargetType(Class<?> targetType) {
return JsonGenerator.class.isAssignableFrom( targetType );
}
@Override
public <T> T fromString(CharSequence charSequence, Type type) {
try {
return objectMapper.readValue( charSequence.toString(), objectMapper.constructType( type ) );
}
catch (JsonProcessingException e) {
throw new IllegalArgumentException( "Could not deserialize string to java type: " + type, e );
}
}
@Override
public <T> String toString(T value, Type type) {
try {
return objectMapper.writerFor( objectMapper.constructType( type ) ).writeValueAsString( value );
}
catch (JsonProcessingException e) {
throw new IllegalArgumentException( "Could not serialize object of java type: " + type, e );
}
}
}
View on GitHub (pinned to fad1729dce)
Solutions
- Inspect the failing row's JSON column and fix the data so it matches the attribute's Java type (shape, field names, types).
- Align the entity attribute type with what is actually stored (e.g. switch List<Integer> vs Pojo), or make the type tolerant with @JsonIgnoreProperties(ignoreProperties = true) and a default constructor/@JsonCreator.
- If you constructed JacksonOsonFormatMapper(ObjectMapper) yourself, register the modules the type needs (e.g. JavaTimeModule via findModules or registerModule).
- If you need full control, plug a custom FormatMapper through the hibernate.type.json_format_mapper setting instead of relying on the default.
- Run a data-repair migration for rows whose JSON predates a type change.
Example fix
// before - column holds [1,2,3] but the attribute expects an object
@Entity
class Doc {
@JdbcTypeCode(SqlTypes.JSON)
MyPojo payload; // readValue fails -> IllegalArgumentException
}
// after - attribute type matches the stored JSON shape
@Entity
class Doc {
@JdbcTypeCode(SqlTypes.JSON)
List<Integer> payload; // matches the stored array
} Defensive patterns
Strategy: try-catch
Validate before calling
// When importing/migrating data into a JSON column, verify it parses
// against the attribute type before inserting:
try {
ObjectMapper mapper = new ObjectMapper().findAndRegisterModules();
MyPojo check = mapper.readValue( candidateJson, MyPojo.class );
} catch ( JsonProcessingException e ) {
throw new IllegalArgumentException( "Row will fail on load: " + e.getOriginalMessage(), e );
} Try / catch
try {
Doc doc = session.find( Doc.class, id );
} catch ( IllegalArgumentException e ) {
if ( e.getCause() instanceof com.fasterxml.jackson.core.JsonProcessingException jpe ) {
// column data <-> attribute type mismatch: log row id and jpe.getOriginalMessage()
} else throw e;
} Prevention
- Round-trip test every JSON-mapped attribute type (serialize + deserialize) in unit tests before shipping mapping changes.
- Never hand-edit JSON columns; run migrations through the entity or a validated import path.
- When swapping the mapper (jackson vs jsonb vs jackson-oson), re-run integration tests against existing data.
- Keep the attribute type tolerant: @JsonIgnoreProperties(ignoreProperties = true) and an explicit default constructor.
When it happens
Trigger: Loading an entity whose SqlTypes.JSON attribute column contains malformed JSON or JSON whose shape does not match the attribute type (e.g. a JSON array stored for a POJO field); the attribute type not being Jackson-deserializable (no default constructor, missing @JsonCreator, java.time fields without JavaTimeModule registered on the ObjectMapper passed to new JacksonOsonFormatMapper(ObjectMapper)); hand-edited or externally migrated column data.
Common situations: Changing the entity field type (e.g. Map to POJO) without migrating the JSON already stored in the Oracle column; JSON written by another application or an older Hibernate version; supplying a custom ObjectMapper that lacks the modules the previous mapper had; enabling the mapper via hibernate.type.json_format_mapper=jackson-oson against dirty data.
Related errors
- Could not serialize object of java type: {}
- Unsupportd target type
- Unsupportd source type
- No more item in JSON document
- Unknown OSON event: {}
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/c4ba1aca192d7fcd.
Report an issue: GitHub.