{"record":{"id":"cb2685ba70052046","repo":"quarkusio/quarkus","slug":"i-cannot-convert-anything-from-xml","errorCode":null,"errorMessage":"I cannot convert anything from XML.","messagePattern":"I cannot convert anything from XML\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"integration-tests/jpa-postgresql-withxml/src/main/java/io/quarkus/it/jpa/postgresql/otherpu/XmlFormatMapper.java","lineNumber":16,"sourceCode":"package io.quarkus.it.jpa.postgresql.otherpu;\n\nimport org.hibernate.type.descriptor.WrapperOptions;\nimport org.hibernate.type.descriptor.java.JavaType;\nimport org.hibernate.type.format.FormatMapper;\n\nimport io.quarkus.hibernate.orm.PersistenceUnitExtension;\nimport io.quarkus.hibernate.orm.XmlFormat;\n\n@XmlFormat\n@PersistenceUnitExtension(\"other\")\npublic class XmlFormatMapper implements FormatMapper {\n\n    @Override\n    public <T> T fromString(CharSequence charSequence, JavaType<T> javaType, WrapperOptions wrapperOptions) {\n        throw new UnsupportedOperationException(\"I cannot convert anything from XML.\");\n    }\n\n    @Override\n    public <T> String toString(T value, JavaType<T> javaType, WrapperOptions wrapperOptions) {\n        throw new UnsupportedOperationException(\"I cannot convert anything to XML.\");\n    }\n}\n","sourceCodeStart":1,"sourceCodeEnd":24,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/integration-tests/jpa-postgresql-withxml/src/main/java/io/quarkus/it/jpa/postgresql/otherpu/XmlFormatMapper.java#L1-L24","documentation":"XmlFormatMapper.fromString unconditionally throws UnsupportedOperationException('I cannot convert anything from XML.'). This mapper is a deliberately degenerate FormatMapper registered via @PersistenceUnitExtension(\"other\") with @XmlFormat for the 'other' persistence unit; it is used by the integration test to prove that Hibernate calls the custom mapper. Any code path that deserializes an XML-format column value from that persistence unit will always fail with this exception.","triggerScenarios":"Reading (deserializing) an entity property that Hibernate maps with the XML format mapper from the 'other' persistence unit — e.g. loading an EntityWithXmlOtherPU row whose property must be converted from the stored string back to Java via fromString.","commonSituations":"Queries that select entities with @JdbcTypeCode(SqlTypes.JSON)-style XML-mapped properties from the 'other' PU; accidentally wiring this test mapper (or copying it) into a real application PU where XML conversion should actually work.","solutions":["Do not use XmlFormatMapper in production code — it is a test-only mapper that intentionally fails","Implement fromString properly in your custom FormatMapper (e.g. parse the CharSequence with a real XML/JSON parser)","Check the @PersistenceUnitExtension qualifier so the real mapper, not the throwing test one, is bound to your persistence unit","If reading should be supported but writing not, implement fromString and keep throwing only in toString"],"exampleFix":"// before\n@Override\npublic <T> T fromString(CharSequence charSequence, JavaType<T> javaType, WrapperOptions wrapperOptions) {\n    throw new UnsupportedOperationException(\"I cannot convert anything from XML.\");\n}\n// after\n@Override\npublic <T> T fromString(CharSequence charSequence, JavaType<T> javaType, WrapperOptions wrapperOptions) {\n    return (T) xmlMapper.readValue(charSequence.toString(), javaType.getJavaClass());\n}","handlingStrategy":"try-catch","validationCode":"// Check which FormatMapper is bound to your persistence unit before relying on XML reads\nif (formatMapper instanceof XmlFormatMapper) {\n    throw new IllegalStateException(\"Test-only XmlFormatMapper is active; XML reads are not supported\");\n}","typeGuard":"static boolean supportsReading(FormatMapper mapper) {\n    return !(mapper instanceof XmlFormatMapper);\n}","tryCatchPattern":"try {\n    EntityWithXmlOtherPU e = em.find(EntityWithXmlOtherPU.class, id);\n} catch (UnsupportedOperationException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"I cannot convert anything from XML\")) {\n        // fall back to a working mapper or raw column read\n    } else {\n        throw e;\n    }\n}","preventionTips":["Never ship test-only mappers annotated with @PersistenceUnitExtension in production artifacts","Implement both directions (toString/fromString) in production FormatMapper implementations","Verify mapper selection per persistence unit during development with a smoke read/write test","Document intentionally unsupported directions in the mapper instead of throwing bare UnsupportedOperationException"],"tags":["hibernate-orm","format-mapper","unsupported-operation","deserialization"],"backgroundTag":"unsupported-operation","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}