{"record":{"id":"962a7d6244a2406e","repo":"quarkusio/quarkus","slug":"unable-to-serialize-objects-of-type-param-getcla","errorCode":null,"errorMessage":"Unable to serialize objects of type ${param.getClass()} to bytecode as it has no default constructor","messagePattern":"Unable to serialize objects of type (.+?) to bytecode as it has no default constructor","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"core/deployment/src/main/java/io/quarkus/deployment/recording/BytecodeRecorderImpl.java","lineNumber":1593,"sourceCode":"                        }\n                    } else {\n                        try {\n                            param.getClass().getDeclaredConstructor();\n                            out = method.newInstance(ofConstructor(param.getClass()));\n                        } catch (NoSuchMethodException e) {\n                            //fallback for collection types, such as unmodifiableMap\n                            if (SortedMap.class.isAssignableFrom(expectedType)) {\n                                out = method.newInstance(ofConstructor(TreeMap.class));\n                            } else if (Map.class.isAssignableFrom(expectedType)) {\n                                out = method.newInstance(ofConstructor(LinkedHashMap.class));\n                            } else if (List.class.isAssignableFrom(expectedType)) {\n                                out = method.newInstance(ofConstructor(ArrayList.class));\n                            } else if (SortedSet.class.isAssignableFrom(expectedType)) {\n                                out = method.newInstance(ofConstructor(TreeSet.class));\n                            } else if (Set.class.isAssignableFrom(expectedType)) {\n                                out = method.newInstance(ofConstructor(LinkedHashSet.class));\n                            } else {\n                                throw new RuntimeException(\"Unable to serialize objects of type \" + param.getClass()\n                                        + \" to bytecode as it has no default constructor\");\n                            }\n                        }\n                    }\n                }\n                return out;\n            }\n        };\n\n        //now return the actual deferred parameter that represents the result of construction\n        return new DeferredArrayStoreParameter(param, expectedType) {\n\n            @Override\n            void doPrepare(MethodContext context) {\n                //this is where the object construction happens\n                //first create the actual object\n                for (SerializationStep i : ctorSetupSteps) {\n                    i.prepare(context);","sourceCodeStart":1575,"sourceCodeEnd":1611,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/core/deployment/src/main/java/io/quarkus/deployment/recording/BytecodeRecorderImpl.java#L1575-L1611","documentation":"The recorder can only rebuild collection-like or bean objects at runtime if it can instantiate them. For a type it does not specially handle (List/Set/Map/known interfaces) and that has no default constructor, there is no way to create the instance during replay, so serialization is refused.","triggerScenarios":"Passing an object whose class has no no-arg constructor and is not a List/SortedSet/Set/Map or a registered-recordable type into a @Record method — e.g. a custom immutable collection or a class with only parameterized constructors.","commonSituations":"Custom collection implementations; value objects with only all-args constructors; third-party types placed on config classes.","solutions":["Add a public no-arg constructor to the class and populate via setters","Use a standard type (ArrayList/HashSet/HashMap or their interfaces) instead of the custom type","Register the class for recording with an explicit recordable constructor (@Inject constructor or registered paramGenerator)","Convert the value to a supported representation before recording"],"exampleFix":"// before\nnew CustomIntList(42) // no default ctor\n// after\nList<Integer> list = new ArrayList<>(); // default ctor, standard type","handlingStrategy":"validation","validationCode":"boolean instantiable(Class<?> c) {\n    if (List.class.isAssignableFrom(c) || Set.class.isAssignableFrom(c)\n        || Map.class.isAssignableFrom(c)) return true;\n    try { c.getConstructor(); return true; } catch (NoSuchMethodException e) { return false; }\n}\nif (!instantiable(value.getClass())) throw new IllegalStateException(\"No default ctor: \" + value.getClass());","typeGuard":"boolean hasDefaultConstructor(Class<?> c) {\n    try { c.getDeclaredConstructor(); return true; }\n    catch (NoSuchMethodException e) { return false; }\n}","tryCatchPattern":"try {\n    recorder.record(value);\n} catch (RuntimeException e) {\n    if (String.valueOf(e.getMessage()).contains(\"has no default constructor\")) {\n        throw new IllegalStateException(\"Add a no-arg constructor or use a standard type for \" + value.getClass(), e);\n    }\n    throw e;\n}","preventionTips":["Prefer standard collection types (ArrayList, HashSet, HashMap) in recorded values","Give recorded value classes a public no-arg constructor","Register explicit recordable constructors for immutable types"],"tags":["quarkus","bytecode-recording","constructor"],"backgroundTag":"missing-default-constructor","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"}