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

  1. If this is the intentional test mapper, leave it — the test asserts this exact message; the error is expected
  2. If seen in application code, remove XmlFormatMapper and register a real FormatMapper implementation
  3. Verify @PersistenceUnitExtension qualifiers so the throwing mapper is not associated with a persistence unit that needs working XML conversion
  4. 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

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


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/6cc427f24b2c80e6. Report an issue: GitHub.