@BeanIgnore Annotation
The @BeanIgnore annotation
(org.apache.juneau.commons.bean) excludes a class, field, method, or constructor from bean introspection —
the model-side decision about whether something participates in bean detection at all.
This is the model-side annotation. Format-side concerns — skipping a type entirely at the wire-format layer
regardless of whether it's a bean — live on the sibling annotation
@MarshalledIgnore
(org.apache.juneau.marshall), described at the end of this page. The two annotations are independent and may
be combined.
Fields and Methods
When applied to a field or method, @BeanIgnore excludes it from bean property discovery.
public class MyBean {
// Not a bean property!
@BeanIgnore
public String foo;
// Not a bean property!
@BeanIgnore
public String getBar() {...}
}
Constructors
When applied to a constructor, @BeanIgnore excludes it from constructor detection (i.e. it won't be
considered a candidate bean constructor).
public class MyBean {
public MyBean() {...}
// Excluded from constructor detection.
@BeanIgnore
public MyBean(String foo) {...}
}
Classes
When applied to a class, @BeanIgnore marks the class as not a bean for modeling purposes. The marshaller
falls through to its other type-detection logic (object swaps, @BeanType-style hints,
@Marshalled(as=MarshalledAs.STRING), etc.) instead of treating the class as a bean — it does not by itself
suppress output the way @MarshalledIgnore does.
// Not treated as a bean for modeling purposes.
// The marshaller still tries to render it, e.g. via toString() or an installed swap.
@BeanIgnore
public class MyType {...}
In versions prior to 10.0, @BeanIgnore on a class caused the object to be serialized via toString() rather
than as a bean — that historical behavior is what the current @BeanIgnore-on-class semantics above describe.
If you specifically want the wire format to render null for a type regardless of bean-modeling status, use
@MarshalledIgnore (see below) instead. If you want the explicit toString() serialization behavior, use
@Marshalled(as=MarshalledAs.STRING):
// Serialize as toString() value.
@Marshalled(as=MarshalledAs.STRING)
public class MyType {
@Override public String toString() { return "my-value"; }
}
Private fields and accessors (ignoreAccessors)
By default, @BeanIgnore on a field only excludes that field from field-based bean discovery. Public (or
otherwise visible) getters/setters can still expose the same logical property — for example when
beanFieldVisibility is NONE and only methods are used. That matches patterns such as @BeanIgnore on private
f5…f8 with public getF5() while still serializing f5 via the getter.
To also exclude the matching JavaBean accessor pair from metadata (so the property does not appear in
serialization or parsing), set ignoreAccessors = true on the field annotation:
public class MyBean {
public String visible = "ok";
// Hidden from Juneau bean metadata: no "foo" in serialization/parsing
@BeanIgnore(ignoreAccessors = true)
private String foo = "secret";
public String getFoo() {
return foo;
}
public void setFoo(String value) {
foo = value;
}
}
The logical property name is derived from the field the same way as for visible fields: @BeanProp /
@Name on the field, if present, otherwise the marshalling context's PropertyNamer applied to the field name.
That name must match the accessor-derived property name (e.g. field foo with getFoo/setFoo).
Java Records
Ignoring individual record components is not supported during parsing. Because records are immutable, all
components must be provided to the canonical constructor. Applying @BeanIgnore to a record component's
accessor method or field will exclude it from serialization output, but the parser will be unable to instantiate
the record if the component value is missing from the input.
If you need to omit components during parsing, use @BeanCtor with a non-canonical constructor that provides defaults for the omitted components.
Format Side: @MarshalledIgnore
@MarshalledIgnore
(org.apache.juneau.marshall) is a type-level-only annotation (it has no field/method target and no
ignoreAccessors attribute). Serializers output null for instances of the annotated type, and parsers return
null when asked to instantiate it — this is a wire-format concern independent of whatever the bean-modeling
layer would otherwise do with the type.
// Suppressed entirely at the wire-format layer — serializes as null.
@MarshalledIgnore
public class MyType {...}
Because the two annotations are independent, they combine as follows:
@MarshalledIgnorealone — the class still participates in bean detection (it may be treated as a bean by the modeling layer), but the marshaller emitsnull.@BeanIgnorealone — the class is not a bean for modeling purposes, but the marshaller still tries to render it (typically viatoString()or an installed swap).- Both — the class is not a bean and the marshaller emits
null.
- Java Records Support - Full documentation on Java records support.
- @BeanType Annotation - The model-side/format-side split pattern this page follows.