{"record":{"id":"628e2c47190c1814","repo":"alibaba/nacos","slug":"100","errorCode":"100","errorMessage":"Nacos serialize for class [%s] failed. ","messagePattern":"Nacos serialize for class \\[(.+?)\\] failed\\. ","errorType":"error_code","errorClass":"NacosSerializationException","httpStatus":null,"severity":"error","filePath":"common/src/main/java/com/alibaba/nacos/common/json/Jackson2JsonAdapter.java","lineNumber":130,"sourceCode":"    }\n    \n    @Override\n    public void registerSubtype(NacosJsonSubtype subtype) {\n        NamedType namedType = new NamedType(subtype.getSubtype(), subtype.getTypeName());\n        mapper.registerSubtypes(namedType);\n        canonicalMapper.registerSubtypes(namedType);\n    }\n    \n    private JavaType constructJavaType(Type type) {\n        return mapper.constructType(type);\n    }\n    \n    private <T> T write(Object obj, JsonWriter<T> writer) {\n        try {\n            return writer.write();\n        } catch (JsonProcessingException e) {\n            Class<?> serializedClass = obj == null ? Object.class : obj.getClass();\n            throw new NacosSerializationException(serializedClass, e);\n        }\n    }\n    \n    private <T> T read(JsonReader<T> reader, Class<?> cls) {\n        try {\n            return reader.read();\n        } catch (Exception e) {\n            throw new NacosDeserializationException(cls, e);\n        }\n    }\n    \n    private <T> T read(JsonReader<T> reader, Type type) {\n        try {\n            return reader.read();\n        } catch (Exception e) {\n            throw new NacosDeserializationException(type, e);\n        }\n    }","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/common/src/main/java/com/alibaba/nacos/common/json/Jackson2JsonAdapter.java#L112-L148","documentation":"Thrown by Jackson2JsonAdapter.write() when the underlying Jackson ObjectMapper throws a JsonProcessingException during serialization. The adapter wraps it as NacosSerializationException (error code 100) carrying the class being serialized (Object.class when the object was null). This is Nacos's JSON backend failing to turn an object into JSON.","triggerScenarios":"Calling any Nacos JSON serialize path (e.g. Jackson2JsonAdapter.toJson / serialization used by the HTTP client or gRPC payload builders) on an object whose type Jackson cannot handle: self-referencing cycles, missing no-arg constructor, JDK type not registered, fields of types with no serializer.","commonSituations":"Serializing a model with a circular reference (parent->child->parent); a POJO with only an all-args constructor and no default constructor; Java 8 date/time or Guava Optional fields without the jackson-datatype-jsr310 / registered module; serializing an anonymous/inner class capturing an enclosing instance.","solutions":["Inspect the wrapped cause (NacosSerializationException.getCause() / throwable) to see the exact JsonProcessingException message, then address it (add @JsonIgnore for cycles, @JsonCreator for constructors).","Add a public no-argument constructor to the serialized class.","Register the needed Jackson module (e.g. JavaTimeModule for java.time) on the mapper configuration used by the adapter.","Break circular references with @JsonManagedReference/@JsonBackReference or @JsonIdentityInfo.","Reproduce with a standalone ObjectMapper.writeValueAsString(obj) to isolate from Nacos plumbing."],"exampleFix":"// before\npublic class Node { Node parent; List<Node> children; } // infinite recursion\nString json = jsonAdapter.toJson(node); // NacosSerializationException code 100\n\n// after\npublic class Node {\n    @JsonBackReference Node parent;\n    @JsonManagedReference List<Node> children;\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    String json = jsonAdapter.toJson(obj);\n} catch (NacosSerializationException e) {\n    log.error(\"Serialize failed for class {}\", e.getSerializedClass(), e.getCause());\n    throw e;\n}","preventionTips":["Give serialized POJOs a public no-argument constructor.","Break object cycles with @JsonIgnore/@JsonManagedReference/@JsonBackReference.","Register needed Jackson modules (jsr310 for java.time) on the mapper used by the adapter.","Reproduce serialization standalone with ObjectMapper.writeValueAsString before integrating."],"tags":["serialization","jackson","json","runtime"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}