FasterXML/jackson-databind · error · IllegalStateException
_anySetter already set to non-null
Error message
_anySetter already set to non-null
What it means
Thrown by BeanDeserializerBuilder.setAnySetter as IllegalStateException when setAnySetter is invoked twice with non-null values. A bean can have at most one 'any setter' (the catch-all for unknown properties, via @JsonAnySetter); encountering a second candidate means the type declares multiple any-setter members.
Source
Thrown at src/main/java/tools/jackson/databind/deser/BeanDeserializerBuilder.java:299
/**
* Method called by deserializer factory, when a "creator property"
* (something that is passed via constructor- or factory method argument;
* instead of setter or field).
*<p>
* Default implementation does not do anything; we may need to revisit this
* decision if these properties need to be available through accessors.
* For now, however, we just have to ensure that we don't try to resolve
* types that masked setter/field has (see [JACKSON-700] for details).
*/
public void addCreatorProperty(SettableBeanProperty prop)
{
addProperty(prop);
}
public void setAnySetter(SettableAnyProperty s)
{
if (_anySetter != null && s != null) {
throw new IllegalStateException("_anySetter already set to non-null");
}
_anySetter = s;
}
public void setIgnoreUnknownProperties(boolean ignore) {
_ignoreAllUnknown = ignore;
}
public void setValueInstantiator(ValueInstantiator inst) {
_valueInstantiator = inst;
_propsBasedCreatorParams = inst.getFromObjectArguments(_config);
}
public void setObjectIdReader(ObjectIdReader r) {
_objectIdReader = r;
}
public void setPOJOBuilder(AnnotatedMethod buildMethod, JsonPOJOBuilder.Value config) {View on GitHub (pinned to 87876ca5c0)
Solutions
- Ensure the target type declares exactly one @JsonAnySetter member (typically a single-arg Map setter or a (String, Object) method).
- Remove redundant @JsonAnySetter annotations after refactoring.
- Check mixins applied to the type do not add a second any-setter.
Example fix
// before: two any-setters
class Pojo {
@JsonAnySetter private Map<String,Object> extra;
@JsonAnySetter public void add(String k, Object v){...}
}
// after: single any-setter
class Pojo {
@JsonAnySetter public void add(String k, Object v){...}
} Defensive patterns
Strategy: validation
Validate before calling
// Count @JsonAnySetter members on the type (and mixins).
long anySetters = Arrays.stream(cls.getDeclaredMethods())
.filter(m -> m.isAnnotationPresent(JsonAnySetter.class)).count();
if (anySetters > 1) {
throw new IllegalStateException(cls + " has multiple @JsonAnySetter methods");
} Prevention
- Declare at most one @JsonAnySetter per type.
- Remove stale @JsonAnySetter annotations after refactoring.
- Check mixins for stray any-setter declarations.
When it happens
Trigger: A bean declares more than one @JsonAnySetter (e.g., a field of type Map plus a setter method, or two any-setter methods), causing the factory to call setAnySetter twice with non-null.
Common situations: Adding @JsonAnySetter to both a Map field and a method; refactoring a setter into a field but leaving the old annotation; mixins/merged types that collectively declare two any-setters; combining @JsonAnySetter with @JsonSetter on the same logical slot.
Related errors
- Duplicate property '${prop.getName()}' for ${_beanDescRef.ge
- Invalid Object Id definition for %s: cannot find property wi
- Unsuitable method ({}) decorated with @JsonCreator (for Enum
- Cannot deserialize Class ${type.getName()} (of type ${typeSt
- Cannot deserialize Proxy class ${type.getName()} as a Bean
AI-assisted analysis of FasterXML/jackson-databind@87876ca5c0 (2026-08-11).
Data as JSON: /api/errors/920ca1ee467b3b9a.
Report an issue: GitHub.