{"record":{"id":"2a6b388f5a789ff0","repo":"hibernate/hibernate-orm","slug":"unsupportd-target-type","errorCode":null,"errorMessage":"Unsupportd target type ","messagePattern":"Unsupportd target type ","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/type/format/FormatMapper.java","lineNumber":66,"sourceCode":"\t * Checks that this mapper supports a type as a source type.\n\t * @param sourceType the source type\n\t * @return <code>true</code> if the type is supported, false otherwise.\n\t */\n\tdefault boolean supportsSourceType(Class<?> sourceType) {\n\t\treturn false;\n\t};\n\n\t/**\n\t * Checks that this mapper supports a type as a target type.\n\t * @param targetType the target type\n\t * @return <code>true</code> if the type is supported, false otherwise.\n\t */\n\tdefault boolean supportsTargetType(Class<?> targetType) {\n\t\treturn false;\n\t}\n\n\tdefault <T> void writeToTarget(T value, JavaType<T> javaType, Object target, WrapperOptions options) throws IOException {\n\t\tthrow new UnsupportedOperationException( \"Unsupportd target type \" + target.getClass() );\n\t};\n\n\tdefault <T> T readFromSource(JavaType<T> javaType, Object source, WrapperOptions options) throws IOException {\n\t\tthrow new UnsupportedOperationException( \"Unsupportd source type \" + source.getClass() );\n\t};\n}\n","sourceCodeStart":48,"sourceCodeEnd":73,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/type/format/FormatMapper.java#L48-L73","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Override writeToTarget (and supportsTargetType to advertise it) in your FormatMapper for the targets Hibernate passes","Use the built-in mapper matching the target type - Jackson mapper for String/Writer, the Oracle OSON mapper for OracleJsonGenerator","Keep the hibernate.type.json_format_mapper setting consistent with the dialect's storage format"],"exampleFix":"// before - custom mapper without target support\npublic class MyMapper implements FormatMapper {\n    // only fromString/toString implemented -> 'Unsupportd target type'\n}\n\n// after\npublic class MyMapper implements FormatMapper {\n    @Override public boolean supportsTargetType(Class<?> t) {\n        return OracleJsonGenerator.class.isAssignableFrom(t);\n    }\n    @Override public <T> void writeToTarget(T value, JavaType<T> javaType, Object target, WrapperOptions options) throws IOException {\n        // write through a JsonDocumentWriter backed by (OracleJsonGenerator) target\n    }\n    // ...\n}","handlingStrategy":"validation","validationCode":"FormatMapper mapper = sessionFactory.getSessionFactoryOptions().getJsonFormatMapper();\nif (!mapper.supportsTargetType(OracleJsonGenerator.class)) {\n    // do not stream; fall back to the string API\n    String json = mapper.toString(value, javaType, options);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Implement supportsTargetType truthfully alongside writeToTarget in custom FormatMappers","Prefer built-in format mappers unless you need a custom one","Re-test aggregate write paths against your target dialect after upgrading Hibernate"],"tags":["hibernate","json","format-mapper","oracle","oson","configuration"],"backgroundTag":"json-format-mapper-unsupported-target","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}