quarkusio/quarkus · error · UnsupportedOperationException
I cannot convert anything to XML.
Error message
I cannot convert anything to XML.
What it means
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.
Source
Thrown at integration-tests/jpa-postgresql-withxml/src/main/java/io/quarkus/it/jpa/postgresql/otherpu/XmlFormatMapper.java:21
import org.hibernate.type.descriptor.WrapperOptions;
import org.hibernate.type.descriptor.java.JavaType;
import org.hibernate.type.format.FormatMapper;
import io.quarkus.hibernate.orm.PersistenceUnitExtension;
import io.quarkus.hibernate.orm.XmlFormat;
@XmlFormat
@PersistenceUnitExtension("other")
public class XmlFormatMapper implements FormatMapper {
@Override
public <T> T fromString(CharSequence charSequence, JavaType<T> javaType, WrapperOptions wrapperOptions) {
throw new UnsupportedOperationException("I cannot convert anything from XML.");
}
@Override
public <T> String toString(T value, JavaType<T> javaType, WrapperOptions wrapperOptions) {
throw new UnsupportedOperationException("I cannot convert anything to XML.");
}
}
View on GitHub (pinned to e1c734241f)
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
Example fix
// before
@Override
public <T> String toString(T value, JavaType<T> javaType, WrapperOptions wrapperOptions) {
throw new UnsupportedOperationException("I cannot convert anything to XML.");
}
// after
@Override
public <T> String toString(T value, JavaType<T> javaType, WrapperOptions wrapperOptions) {
return xmlMapper.writeValueAsString(value);
} Defensive patterns
Strategy: try-catch
Validate before calling
// Verify the active FormatMapper for the PU supports writes before persisting
if (formatMapper instanceof XmlFormatMapper) {
throw new IllegalStateException("XmlFormatMapper cannot serialize to XML; check PU wiring");
} Type guard
static boolean supportsWriting(FormatMapper mapper) {
return !(mapper instanceof XmlFormatMapper);
} Try / catch
try {
QuarkusTransaction.requiringNew().run(() -> em.persist(entity));
} catch (UnsupportedOperationException e) {
if (e.getMessage() != null && e.getMessage().contains("I cannot convert anything to XML")) {
throw new IllegalStateException("XML serialization not supported for this persistence unit", e);
}
throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- I cannot convert anything from XML.
- This isn't used for schema generation - see SessionFactoryOb
- This method is not available at runtime in Quarkus
- I cannot convert anything from JSON.
- I cannot convert anything to JSON.
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/6cc427f24b2c80e6.
Report an issue: GitHub.