{"record":{"id":"6cc427f24b2c80e6","repo":"quarkusio/quarkus","slug":"i-cannot-convert-anything-to-xml","errorCode":null,"errorMessage":"I cannot convert anything to XML.","messagePattern":"I cannot convert anything to 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":21,"sourceCode":"import 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":3,"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#L3-L24","documentation":"XmlFormatMapper.toString unconditionally throws UnsupportedOperationException('I cannot convert anything to XML.'). The mapper is annotated @XmlFormat and @PersistenceUnitExtension(\"other\"), so it is the FormatMapper selected for the 'other' persistence unit; the integration test relies on it throwing at flush time. Any attempt to persist/serialize a mapped property through this mapper always fails with this exception.","triggerScenarios":"Flushing (INSERT/UPDATE of) an entity from the 'other' persistence unit whose property is serialized via the XML format mapper — e.g. em.persist(otherPU) followed by transaction commit/flush in the jpa-postgresql-withxml test.","commonSituations":"Running the jpa-postgresql-withxml integration test (expected exception); copying this mapper into a real application and then failing to write XML columns; changing PU qualifiers so the throwing mapper is picked up by the wrong persistence unit.","solutions":["If this is the intentional test mapper, leave it — the test asserts this exact message; the error is expected","If seen in application code, remove XmlFormatMapper and register a real FormatMapper implementation","Verify @PersistenceUnitExtension qualifiers so the throwing mapper is not associated with a persistence unit that needs working XML conversion","Implement toString with an actual serializer (e.g. Jackson XML mapper) if write support is needed"],"exampleFix":"// before\n@Override\npublic <T> String toString(T value, JavaType<T> javaType, WrapperOptions wrapperOptions) {\n    throw new UnsupportedOperationException(\"I cannot convert anything to XML.\");\n}\n// after\n@Override\npublic <T> String toString(T value, JavaType<T> javaType, WrapperOptions wrapperOptions) {\n    return xmlMapper.writeValueAsString(value);\n}","handlingStrategy":"try-catch","validationCode":"// Verify the active FormatMapper for the PU supports writes before persisting\nif (formatMapper instanceof XmlFormatMapper) {\n    throw new IllegalStateException(\"XmlFormatMapper cannot serialize to XML; check PU wiring\");\n}","typeGuard":"static boolean supportsWriting(FormatMapper mapper) {\n    return !(mapper instanceof XmlFormatMapper);\n}","tryCatchPattern":"try {\n    QuarkusTransaction.requiringNew().run(() -> em.persist(entity));\n} catch (UnsupportedOperationException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"I cannot convert anything to XML\")) {\n        throw new IllegalStateException(\"XML serialization not supported for this persistence unit\", e);\n    }\n    throw e;\n}","preventionTips":["Confirm the @PersistenceUnitExtension value matches the PU of the entities you persist","Do not reuse the jpa-postgresql-withxml test mapper outside the test module","Add an integration smoke test that round-trips one XML-mapped entity per persistence unit","If the failure is intentional (as in this test), catch and assert on the exact message so future wiring changes surface clearly"],"tags":["hibernate-orm","format-mapper","unsupported-operation","serialization"],"backgroundTag":"unsupported-operation","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}