alibaba/nacos · error · NacosSerializationException

100

100

Error message

Nacos serialize for class [%s] failed. 

What it means

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.

Source

Thrown at common/src/main/java/com/alibaba/nacos/common/json/Jackson2JsonAdapter.java:130

    }
    
    @Override
    public void registerSubtype(NacosJsonSubtype subtype) {
        NamedType namedType = new NamedType(subtype.getSubtype(), subtype.getTypeName());
        mapper.registerSubtypes(namedType);
        canonicalMapper.registerSubtypes(namedType);
    }
    
    private JavaType constructJavaType(Type type) {
        return mapper.constructType(type);
    }
    
    private <T> T write(Object obj, JsonWriter<T> writer) {
        try {
            return writer.write();
        } catch (JsonProcessingException e) {
            Class<?> serializedClass = obj == null ? Object.class : obj.getClass();
            throw new NacosSerializationException(serializedClass, e);
        }
    }
    
    private <T> T read(JsonReader<T> reader, Class<?> cls) {
        try {
            return reader.read();
        } catch (Exception e) {
            throw new NacosDeserializationException(cls, e);
        }
    }
    
    private <T> T read(JsonReader<T> reader, Type type) {
        try {
            return reader.read();
        } catch (Exception e) {
            throw new NacosDeserializationException(type, e);
        }
    }

View on GitHub (pinned to 9b989acdf1)

Solutions

  1. Inspect the wrapped cause (NacosSerializationException.getCause() / throwable) to see the exact JsonProcessingException message, then address it (add @JsonIgnore for cycles, @JsonCreator for constructors).
  2. Add a public no-argument constructor to the serialized class.
  3. Register the needed Jackson module (e.g. JavaTimeModule for java.time) on the mapper configuration used by the adapter.
  4. Break circular references with @JsonManagedReference/@JsonBackReference or @JsonIdentityInfo.
  5. Reproduce with a standalone ObjectMapper.writeValueAsString(obj) to isolate from Nacos plumbing.

Example fix

// before
public class Node { Node parent; List<Node> children; } // infinite recursion
String json = jsonAdapter.toJson(node); // NacosSerializationException code 100

// after
public class Node {
    @JsonBackReference Node parent;
    @JsonManagedReference List<Node> children;
}
Defensive patterns

Strategy: try-catch

Try / catch

try {
    String json = jsonAdapter.toJson(obj);
} catch (NacosSerializationException e) {
    log.error("Serialize failed for class {}", e.getSerializedClass(), e.getCause());
    throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of alibaba/nacos@9b989acdf1 (2026-08-14). Data as JSON: /api/errors/628e2c47190c1814. Report an issue: GitHub.