hibernate/hibernate-orm · error · UnsupportedOperationException

Unsupportd target type

Error message

Unsupportd target type 

What it means

FormatMapper (selected via AvailableSettings.JSON_FORMAT_MAPPER / XML_FORMAT_MAPPER) can stream aggregates directly into a target object (e.g. Oracle's OracleJsonGenerator for binary OSON) via writeToTarget, with supportsTargetType advertising capability. The default implementation throws UnsupportedOperationException 'Unsupportd target type ' + target.getClass() (note the 'Unsupportd' typo in Hibernate's message) whenever the configured mapper does not override it for that target type.

Solutions

  1. Override writeToTarget (and supportsTargetType to advertise it) in your FormatMapper for the targets Hibernate passes
  2. Use the built-in mapper matching the target type - Jackson mapper for String/Writer, the Oracle OSON mapper for OracleJsonGenerator
  3. Keep the hibernate.type.json_format_mapper setting consistent with the dialect's storage format

Example fix

// before - custom mapper without target support
public class MyMapper implements FormatMapper {
    // only fromString/toString implemented -> 'Unsupportd target type'
}

// after
public class MyMapper implements FormatMapper {
    @Override public boolean supportsTargetType(Class<?> t) {
        return OracleJsonGenerator.class.isAssignableFrom(t);
    }
    @Override public <T> void writeToTarget(T value, JavaType<T> javaType, Object target, WrapperOptions options) throws IOException {
        // write through a JsonDocumentWriter backed by (OracleJsonGenerator) target
    }
    // ...
}
Defensive patterns

Strategy: validation

Validate before calling

FormatMapper mapper = sessionFactory.getSessionFactoryOptions().getJsonFormatMapper();
if (!mapper.supportsTargetType(OracleJsonGenerator.class)) {
    // do not stream; fall back to the string API
    String json = mapper.toString(value, javaType, options);
}

Prevention

When it happens

Trigger: The ORM serializes a JSON aggregate to a non-String target while the configured FormatMapper only supports CharSequence output - e.g. the Oracle OSON path handing an OracleJsonGenerator to a Jackson-based custom mapper, or your own FormatMapper that implemented only toString/fromString.

Common situations: Registering a custom FormatMapper (hibernate.type.json_format_mapper) written before the writeToTarget API existed; Oracle JSON binary storage combined with a third-party mapper; version upgrades that started calling writeToTarget for aggregate writes.

Related errors


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

Appendix: source

Thrown at hibernate-core/src/main/java/org/hibernate/type/format/FormatMapper.java:66

	 * Checks that this mapper supports a type as a source type.
	 * @param sourceType the source type
	 * @return <code>true</code> if the type is supported, false otherwise.
	 */
	default boolean supportsSourceType(Class<?> sourceType) {
		return false;
	};

	/**
	 * Checks that this mapper supports a type as a target type.
	 * @param targetType the target type
	 * @return <code>true</code> if the type is supported, false otherwise.
	 */
	default boolean supportsTargetType(Class<?> targetType) {
		return false;
	}

	default <T> void writeToTarget(T value, JavaType<T> javaType, Object target, WrapperOptions options) throws IOException {
		throw new UnsupportedOperationException( "Unsupportd target type " + target.getClass() );
	};

	default <T> T readFromSource(JavaType<T> javaType, Object source, WrapperOptions options) throws IOException {
		throw new UnsupportedOperationException( "Unsupportd source type " + source.getClass() );
	};
}

View on GitHub (pinned to fad1729dce)