FasterXML/jackson-databind · error · UnsupportedOperationException

Cannot call withValueDeserializer() on {}

Error message

Cannot call withValueDeserializer() on {}

What it means

Thrown when withValueDeserializer() is called on a JsonNodeParameterAnyProperty instance. This subclass (used for @JsonAnySetter on a creator parameter that targets a JsonNode/ObjectNode) deliberately throws UnsupportedOperationException because it cannot meaningfully accept a different value deserializer — the node-based any-setter serializes raw JsonNode content and does not delegate to a ValueDeserializer. The base class marks this as 'Should not get called but...' indicating it is a defensive guard against framework misuse.

Source

Thrown at src/main/java/tools/jackson/databind/deser/SettableAnyProperty.java:526

        // Let's override since this is much simpler with JsonNodes
        @Override
        public Object deserialize(JsonParser p, DeserializationContext ctxt)
            throws JacksonException
        {
            return _valueDeserializer.deserialize(p, ctxt);
        }

        @Override
        protected void _set(DeserializationContext ctxt, Object instance, Object propName, Object value)
            throws Exception
        {
            ((ObjectNode) instance).set((String) propName, (JsonNode) value);
        }

        // Should not get called but...
        @Override
        public SettableAnyProperty withValueDeserializer(ValueDeserializer<Object> deser) {
            throw new UnsupportedOperationException("Cannot call withValueDeserializer() on " + getClass().getName());
        }

        @Override
        public int getParameterIndex() { return _parameterIndex; }

        @Override
        public Object createParameterObject() { return _nodeFactory.objectNode(); }
    }
}

View on GitHub (pinned to a50c7d2a1d)

Solutions

  1. Avoid annotating ObjectNode/JsonNode creator parameters with @JsonAnySetter if a custom value deserializer is required.
  2. In any custom factory/modifier code, check the concrete SettableAnyProperty type before calling withValueDeserializer (skip JsonNodeParameterAnyProperty).
  3. Use a Map<String,Object> parameter type instead of ObjectNode if you need custom per-value deserialization on any-setter content.
  4. Register the custom deserializer at the module level so it is already resolved during construction rather than via contextual replacement.

Example fix

// before
@JsonCreator
public MyBean(@JsonAnySetter ObjectNode extra) { ... }
// factory calls withValueDeserializer -> throws

// after: use Map if custom deser needed, or don't customize
@JsonCreator
public MyBean(@JsonAnySetter Map<String,Object> extra) { ... }
Defensive patterns

Strategy: type-guard

Validate before calling

// Check type before calling withValueDeserializer
if (!(settableAnyProp instanceof SettableAnyProperty.JsonNodeParameterAnyProperty)) {
    settableAnyProp = settableAnyProp.withValueDeserializer(deser);
}

Type guard

static boolean canReplaceDeserializer(SettableAnyProperty prop) {
    return !(prop.getClass().getName().contains("JsonNodeParameterAnyProperty"));
}

Try / catch

try {
    prop = prop.withValueDeserializer(deser);
} catch (UnsupportedOperationException e) {
    // JsonNodeParameterAnyProperty cannot be contextualized — skip
}

Prevention

When it happens

Trigger: Defining @JsonAnySetter on a creator constructor parameter whose type is ObjectNode/JsonNode, combined with a custom deserializer or module that attempts contextualization via withValueDeserializer(). Subclassing SettableAnyProperty and routing through the JsonNodeParameterAnyProperty path while the framework attempts contextualizer replacement.

Common situations: Using a custom DeserializerFactory or BeanDeserializerModifier that calls withValueDeserializer on all any-properties indiscriminately. Mixing @JsonAnySetter with @JsonCreator on an ObjectNode-typed parameter while also registering a custom value deserializer.

Related errors


AI-assisted analysis of FasterXML/jackson-databind@a50c7d2a1d (2026-08-06). Data as JSON: /api/errors/65fb2f8f36066349. Report an issue: GitHub.