quarkusio/quarkus · warning · UnsupportedOperationException

I cannot convert anything to JSON.

Error message

I cannot convert anything to JSON.

What it means

Deliberate UnsupportedOperationException thrown by the test's custom JSON FormatMapper when Hibernate tries to serialize a Java object to a JSON string for storage. In the jpa-postgresql test the 'other' persistence unit is configured so JSON writes always fail, letting tests assert transaction rollback behavior. It signals that the registered FormatMapper is a non-functional stub.

Source

Thrown at integration-tests/jpa-postgresql/src/main/java/io/quarkus/it/jpa/postgresql/otherpu/JsonFormatMapper.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.JsonFormat;
import io.quarkus.hibernate.orm.PersistenceUnitExtension;

@JsonFormat
@PersistenceUnitExtension("other")
public class JsonFormatMapper implements FormatMapper {

    @Override
    public <T> T fromString(CharSequence charSequence, JavaType<T> javaType, WrapperOptions wrapperOptions) {
        throw new UnsupportedOperationException("I cannot convert anything from JSON.");
    }

    @Override
    public <T> String toString(T value, JavaType<T> javaType, WrapperOptions wrapperOptions) {
        throw new UnsupportedOperationException("I cannot convert anything to JSON.");
    }
}

View on GitHub (pinned to e1c734241f)

Solutions

  1. Register a working JSON FormatMapper (Jackson-based) instead of the throwing stub
  2. Remove the custom mapper so Hibernate's default JSON serialization is used
  3. If intentionally testing failures, catch UnsupportedOperationException around the transaction and assert its message
Defensive patterns

Strategy: try-catch

Validate before calling

boolean canWrite = mapper != null && !(mapper instanceof JsonFormatMapper);

Try / catch

try {
    tx.run(() -> em.persist(entity));
} catch (UnsupportedOperationException e) {
    if (!e.getMessage().contains("to JSON")) throw e; // unexpected failure
    // handle intentional no-JSON-write PU
}

Prevention

When it happens

Trigger: Flushing or persisting an entity whose attribute is mapped to a JSON column in the 'other' PU: Hibernate calls FormatMapper.toString during binding of the SQL parameter.

Common situations: Hit when running tests that expect the transaction to fail (e.g. hibernateXml-style failure tests), or in real apps if someone registered this stub as their JSON mapper.

Related errors


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