{"record":{"id":"4f182d12997c9ab1","repo":"quarkusio/quarkus","slug":"i-cannot-convert-anything-to-json","errorCode":null,"errorMessage":"I cannot convert anything to JSON.","messagePattern":"I cannot convert anything to JSON\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"warning","filePath":"integration-tests/jpa-postgresql/src/main/java/io/quarkus/it/jpa/postgresql/otherpu/JsonFormatMapper.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.JsonFormat;\nimport io.quarkus.hibernate.orm.PersistenceUnitExtension;\n\n@JsonFormat\n@PersistenceUnitExtension(\"other\")\npublic class JsonFormatMapper 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 JSON.\");\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 JSON.\");\n    }\n}\n","sourceCodeStart":3,"sourceCodeEnd":24,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/integration-tests/jpa-postgresql/src/main/java/io/quarkus/it/jpa/postgresql/otherpu/JsonFormatMapper.java#L3-L24","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Register a working JSON FormatMapper (Jackson-based) instead of the throwing stub","Remove the custom mapper so Hibernate's default JSON serialization is used","If intentionally testing failures, catch UnsupportedOperationException around the transaction and assert its message"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"boolean canWrite = mapper != null && !(mapper instanceof JsonFormatMapper);","typeGuard":null,"tryCatchPattern":"try {\n    tx.run(() -> em.persist(entity));\n} catch (UnsupportedOperationException e) {\n    if (!e.getMessage().contains(\"to JSON\")) throw e; // unexpected failure\n    // handle intentional no-JSON-write PU\n}","preventionTips":["Use the default Hibernate JSON mapper unless a stub is specifically required","Assert mapper registration in tests before asserting failure behavior","Document which persistence units intentionally reject JSON"],"tags":["hibernate-orm","json","format-mapper","test-stub"],"backgroundTag":"unsupported-operation-stub","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"}