alibaba/nacos · error · NacosSerializationException

100

100

Error message

Nacos serialize for class [%s] failed. 

What it means

Thrown by Jackson3JsonAdapterDelegate.write() when the Jackson 3 ObjectMapper throws a JacksonException during serialization. Wrapped as NacosSerializationException (code 100) with the serialized class (Object.class for null). Functionally the Jackson 3 counterpart of error 743, but catches the Jackson 3 base JacksonException rather than Jackson 2's JsonProcessingException.

Source

Thrown at common/src/main/java/com/alibaba/nacos/common/json/Jackson3JsonAdapterDelegate.java:141

        synchronized (subtypes) {
            if (!subtypes.contains(subtype)) {
                subtypes.add(subtype);
            }
            mapper = createObjectMapper(subtypes);
            canonicalMapper = createCanonicalObjectMapper(subtypes);
        }
    }
    
    private JavaType constructJavaType(Type type) {
        return mapper.constructType(type);
    }
    
    private <T> T write(Object obj, JsonWriter<T> writer) {
        try {
            return writer.write();
        } catch (JacksonException 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 (JacksonException e) {
            throw new NacosDeserializationException(cls, e);
        }
    }
    
    private <T> T read(JsonReader<T> reader, Type type) {
        try {
            return reader.read();
        } catch (JacksonException e) {
            throw new NacosDeserializationException(type, e);
        }
    }

View on GitHub (pinned to 9b989acdf1)

Solutions

  1. Read NacosSerializationException.getCause() for the exact JacksonException and offending field/property.
  2. Add a no-argument constructor or a @JsonCreator constructor compatible with Jackson 3.
  3. Register the equivalent Jackson 3 module (jsr310 / parameter-names) on the delegate mapper via the adapter's subtype registration.
  4. Reproduce with a standalone Jackson 3 ObjectMapper to isolate from Nacos.
  5. If a class is incompatible with Jackson 3 and cannot be changed, fall back to the Jackson 2 adapter.

Example fix

// before — Jackson 3, no default constructor
public class Config { private String data; public Config(String data){this.data=data;} }
jsonAdapter.toJson(new Config("x")); // code 100

// after
public class Config {
    public Config() {}
    private String data;
    public Config(String data){this.data=data;}
}
Defensive patterns

Strategy: try-catch

Try / catch

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

Prevention

When it happens

Trigger: Using the JACKSON3 adapter and serializing an object that Jackson 3 cannot handle: circular references, classes lacking a no-arg constructor or @JsonCreator constructor, unsupported JDK types, or types needing a module not registered on the delegate mapper.

Common situations: Switched the JSON backend to Jackson 3 but the model relied on Jackson 2-specific annotations or modules; serializing java.time types without the jsr310-equivalent module for Jackson 3; anonymous/record/class-without-constructor classes under Jackson 3's stricter defaults.

Related errors


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