{"record":{"id":"e295e83743f7ed0a","repo":"quarkusio/quarkus","slug":"cannot-instantiate-json-b-component","errorCode":null,"errorMessage":"Cannot instantiate JSON-B component: ","messagePattern":"Cannot instantiate JSON-B component: ","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"extensions/jsonb/runtime/src/main/java/io/quarkus/jsonb/QuarkusJsonbComponentInstanceCreator.java","lineNumber":57,"sourceCode":"            ArcContainer container = Arc.container();\n            if (container == null) { // this class can be used in unit tests where Arc obviously doesn't run\n                return fallbackCreate(componentClass);\n            }\n\n            InstanceHandle<T> beanHandle = container.instance(componentClass);\n            if (beanHandle.isAvailable()) {\n                beanHandles.add(beanHandle);\n                return beanHandle.get();\n            }\n            return fallbackCreate(componentClass);\n        });\n    }\n\n    private <T> Object fallbackCreate(Class<T> componentClass) {\n        try {\n            return componentClass.getDeclaredConstructor().newInstance();\n        } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {\n            throw new IllegalStateException(\"Cannot instantiate JSON-B component: \" + componentClass, e);\n        }\n    }\n\n}\n","sourceCodeStart":39,"sourceCodeEnd":62,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/jsonb/runtime/src/main/java/io/quarkus/jsonb/QuarkusJsonbComponentInstanceCreator.java#L39-L62","documentation":"QuarkusJsonbComponentInstanceCreator resolves JSON-B components (Jsonb, JsonbBuilder, custom components) from CDI; fallbackCreate is a last resort that tries a no-arg constructor. When reflection-based instantiation fails (abstract class, missing no-arg constructor, throwing constructor, illegal access), it throws IllegalStateException 'Cannot instantiate JSON-B component: <class>'. This almost always means a custom JSON-B component was registered that Quarkus cannot construct.","triggerScenarios":"Registering a custom JsonbConfig component, JsonbAdapter, JsonbSerializer/Deserializer, or instance creator class that has no public no-arg constructor, is abstract, or whose constructor throws; and the component was not available as a CDI bean so the fallback path was used.","commonSituations":"User adds a JSON-B serializer/adapter class with only constructor arguments and registers it globally; upgrading Quarkus/Yasson where the component resolution path changed; a component class throwing inside its constructor (e.g. reading a missing config).","solutions":["Give the component class a public no-arg constructor and make it concrete (non-abstract)","Register the component instance via JsonbConfig.withSerializers/withAdapters using an explicit instance instead of relying on class-based registration","Make the component a CDI bean and configure it through Quarkus's JSON-B CDI integration instead of the fallback path","Check the cause chain for the exception thrown inside the component constructor"],"exampleFix":"// before\npublic class ZonedDateTimeSerializer implements JsonbSerializer<ZonedDateTime> {\n    private final ZoneId zone; // no no-arg ctor\n    ...\n}\n// after\npublic class ZonedDateTimeSerializer implements JsonbSerializer<ZonedDateTime> {\n    public ZonedDateTimeSerializer() { this.zone = ZoneId.systemDefault(); }\n    ...\n}","handlingStrategy":"validation","validationCode":"static <T> boolean canInstantiate(Class<T> c) {\n    try {\n        c.getDeclaredConstructor().newInstance();\n        return true;\n    } catch (ReflectiveOperationException | RuntimeException e) {\n        return false;\n    }\n}","typeGuard":"static <T> boolean hasPublicNoArgCtor(Class<T> c) {\n    try { return java.lang.reflect.Modifier.isPublic(c.getModifiers())\n        && !java.lang.reflect.Modifier.isAbstract(c.getModifiers())\n        && c.getDeclaredConstructor().getParameterCount() == 0; }\n    catch (NoSuchMethodException e) { return false; }\n}","tryCatchPattern":"try {\n    // Quarkus JSON-B setup that triggers component creation\n} catch (IllegalStateException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Cannot instantiate JSON-B component:\")) {\n        log.errorf(e.getCause(), \"Fix component %s: needs public no-arg ctor or explicit registration\", e.getMessage());\n    } else throw e;\n}","preventionTips":["Give JSON-B components a public no-arg constructor and keep them concrete","Register instances explicitly via JsonbConfig.withSerializers/withAdapters instead of relying on fallback reflection","Keep constructors side-effect free (no config/file reads that can throw)","Add a unit test that instantiates every registered JSON-B component reflectively"],"tags":["jsonb","cdi","reflection","quarkus"],"backgroundTag":"jsonb-component-instantiation-failed","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}