Annotation Interface BeanConfig
The bean-modeling sibling of @MarshalledConfig.
Where @MarshalledConfig (in dictionary, swaps, typePropertyName, locale, mediaType,
and timeZone), this annotation carries the attributes that describe how the bean MODEL is
detected and introspected — visibility settings, required-properties toggles, fluent-setter detection,
property naming, not-bean exclusions, etc.
Splitting the annotations lets a class/method participate in bean-modeling configuration without
dragging in any marshalling concerns, and lets the bean-modeling layer live in
Can be used in the following locations:
- Classes and methods (typically REST classes/methods).
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionMinimum bean class visibility.Minimum bean constructor visibility.Minimum bean field visibility.BeanMap.put() returns old property value.Minimum bean method visibility.Beans require no-arg constructors.Beans require Serializable interface.Beans require setters for getters.Beans don't require at least one property.Don't silently ignore missing setters.Don't ignore transient fields.Don't ignore unknown properties with null values.Don't use interface proxies.Find fluent setters.Ignore invocation errors on getters.Ignore invocation errors on setters.Ignore unknown properties.Ignore unknown enum values.Class<?>[]Identifies a set of interfaces.Class<?>[]Bean class exclusions.Class<?>[]Replace classes that should not be considered beans.String[]Bean package exclusions.String[]Replace packages whose classes should not be considered beans.Class<? extends PropertyNamer>Bean property namer.intOptional rank for this config.Record component order.Disable sorted bean properties.Use Java Introspector.Schema validation mode.
-
Element Details
-
beanClassVisibility
Minimum bean class visibility.Classes are not considered beans unless they meet the minimum visibility requirements.
For example, if the visibility is
PUBLIC and the bean class isprotected , then the class will not be interpreted as a bean class and be serialized as a string.
Use this setting to reduce the visibility requirement."PUBLIC" (default)"PROTECTED" "DEFAULT" "PRIVATE"
Notes:
-
Supports VarResolver.DEFAULT (e.g.
"$C{myConfigVar}" ).
- Returns:
- The annotation value.
- Default:
- ""
-
beanConstructorVisibility
Minimum bean constructor visibility.Only look for constructors with the specified minimum visibility.
This setting affects the logic for finding no-arg constructors for bean.
Normally, onlypublic no-arg constructors are used.
Use this setting if you want to reduce the visibility requirement."PUBLIC" (default)"PROTECTED" "DEFAULT" "PRIVATE"
Notes:
-
Supports VarResolver.DEFAULT (e.g.
"$C{myConfigVar}" ).
- Returns:
- The annotation value.
- Default:
- ""
-
beanFieldVisibility
Minimum bean field visibility.Only look for bean fields with the specified minimum visibility.
This affects which fields on a bean class are considered bean properties.
Normally onlypublic fields are considered.
Use this setting if you want to reduce the visibility requirement."PUBLIC" (default)"PROTECTED" "DEFAULT" "PRIVATE"
Notes:
-
Supports VarResolver.DEFAULT (e.g.
"$C{myConfigVar}" ).
- Returns:
- The annotation value.
- Default:
- ""
-
beanMapPutReturnsOldValue
BeanMap.put() returns old property value.If
"true" , then theBeanMap.put()method will return old property values.
Otherwise, it returnsnull ."true" "false" (default because it introduces a slight performance penalty during serialization)
Notes:
-
Supports VarResolver.DEFAULT (e.g.
"$C{myConfigVar}" ).
- Returns:
- The annotation value.
- Default:
- ""
-
beanMethodVisibility
Minimum bean method visibility.Only look for bean methods with the specified minimum visibility.
This affects which methods are detected as getters and setters on a bean class.
Normally onlypublic getters and setters are considered.
Use this setting if you want to reduce the visibility requirement."PUBLIC" (default)"PROTECTED" "DEFAULT" "PRIVATE"
Notes:
-
Supports VarResolver.DEFAULT (e.g.
"$C{myConfigVar}" ).
- Returns:
- The annotation value.
- Default:
- ""
-
beansRequireDefaultConstructor
Beans require no-arg constructors.If
"true" , a Java class must implement a default no-arg constructor to be considered a bean.
Otherwise, the bean will be serialized as a string using theObject.toString()method."true" "false" (default)
Notes:
-
Supports VarResolver.DEFAULT (e.g.
"$C{myConfigVar}" ).
- Returns:
- The annotation value.
- Default:
- ""
-
beansRequireSerializable
Beans require Serializable interface.If
"true" , a Java class must implement theSerializableinterface to be considered a bean.
Otherwise, the bean will be serialized as a string using theObject.toString()method."true" "false" (default)
Notes:
-
Supports VarResolver.DEFAULT (e.g.
"$C{myConfigVar}" ).
- Returns:
- The annotation value.
- Default:
- ""
-
beansRequireSettersForGetters
Beans require setters for getters.If
"true" , only getters that have equivalent setters will be considered as properties on a bean.
Otherwise, they will be ignored."true" "false" (default)
Notes:
-
Supports VarResolver.DEFAULT (e.g.
"$C{myConfigVar}" ).
- Returns:
- The annotation value.
- Default:
- ""
-
disableBeansRequireSomeProperties
Beans don't require at least one property.If
"true" , then a Java class doesn't need to contain at least 1 property to be considered a bean.
Otherwise, the bean will be serialized as a string using theObject.toString()method."true" "false" (default)
Notes:
-
Supports VarResolver.DEFAULT (e.g.
"$C{myConfigVar}" ).
- Returns:
- The annotation value.
- Default:
- ""
-
disableIgnoreMissingSetters
Don't silently ignore missing setters.If
"true" , trying to set a value on a bean property without a setter will throw aBeanRuntimeException.
Otherwise it will be sliently ignored."true" "false" (default)
Notes:
-
Supports VarResolver.DEFAULT (e.g.
"$C{myConfigVar}" ).
- Returns:
- The annotation value.
- Default:
- ""
-
disableIgnoreTransientFields
Don't ignore transient fields.If
true , methods and fields marked astransient will not be ignored as bean properties."true" "false" (default)
Notes:
-
Supports VarResolver.DEFAULT (e.g.
"$C{myConfigVar}" ).
- Returns:
- The annotation value.
- Default:
- ""
-
disableIgnoreUnknownNullBeanProperties
Don't ignore unknown properties with null values.If
"true" , trying to set anull value on a non-existent bean property will throw aBeanRuntimeException. Otherwise it will be silently ignored."true" "false" (default)
Notes:
-
Supports VarResolver.DEFAULT (e.g.
"$C{myConfigVar}" ).
- Returns:
- The annotation value.
- Default:
- ""
-
disableInterfaceProxies
Don't use interface proxies.Disables the feature where interfaces will be instantiated as proxy classes through the use of an
InvocationHandlerif there is no other way of instantiating them.
Setting this to"true" causes this to be aBeanRuntimeException."true" "false" (default)
Notes:
-
Supports VarResolver.DEFAULT (e.g.
"$C{myConfigVar}" ).
- Returns:
- The annotation value.
- Default:
- ""
-
findFluentSetters
Find fluent setters.When enabled, fluent setters are detected on beans.
Fluent setters must have the following attributes:
- Public.
- Not static.
- Take in one parameter.
- Return the bean itself.
"true" "false" (default)
Notes:
-
Supports VarResolver.DEFAULT (e.g.
"$C{myConfigVar}" ).
See Also:
- Returns:
- The annotation value.
- Default:
- ""
-
ignoreInvocationExceptionsOnGetters
Ignore invocation errors on getters.If
"true" , errors thrown when calling bean getter methods will silently be ignored.
Otherwise, aBeanRuntimeExceptionis thrown."true" "false" (default)
Notes:
-
Supports VarResolver.DEFAULT (e.g.
"$C{myConfigVar}" ).
- Returns:
- The annotation value.
- Default:
- ""
-
ignoreInvocationExceptionsOnSetters
Ignore invocation errors on setters.If
"true" , errors thrown when calling bean setter methods will silently be ignored.
Otherwise, aBeanRuntimeExceptionis thrown."true" "false" (default)
Notes:
-
Supports VarResolver.DEFAULT (e.g.
"$C{myConfigVar}" ).
- Returns:
- The annotation value.
- Default:
- ""
-
ignoreUnknownBeanProperties
Ignore unknown properties.If
"true" , trying to set a value on a non-existent bean property will silently be ignored.
Otherwise, aRuntimeExceptionis thrown."true" "false" (default)
Notes:
-
Supports VarResolver.DEFAULT (e.g.
"$C{myConfigVar}" ).
- Returns:
- The annotation value.
- Default:
- ""
-
validateSchema
Schema validation mode.If
"true" , bean property values are validated against the constraints declared by@Schemaannotations on those properties. Validation runs during both parsing (value set on the bean) and serialization (value read from the bean).Backed by the typed
JsonSchemabean injuneau-bean-jsonschemaand JSON Schema Draft 2020-12 semantics. Validation failures throwSchemaValidationExceptionwrapped inBeanRuntimeException; the parser surfaces them as parse exceptions and the serializer surfaces them as serialize exceptions.If
juneau-bean-jsonschemais not on the classpath, this setting becomes a silent no-op."true" "false" (default)
Notes:
-
Supports VarResolver.DEFAULT (e.g.
"$C{myConfigVar}" ).
- Returns:
- The annotation value.
- Since:
- 10.0.0
- Default:
- ""
-
ignoreUnknownEnumValues
Ignore unknown enum values.If
"true" , unknown enum values are set tonull instead of throwing an exception."true" "false" (default)
Notes:
-
Supports VarResolver.DEFAULT (e.g.
"$C{myConfigVar}" ).
- Returns:
- The annotation value.
- Default:
- ""
-
interfaces
Class<?>[] interfacesIdentifies a set of interfaces.When specified, only the list of properties defined on the interface class will be used during serialization of implementation classes. Additional properties on subclasses will be ignored.
// Parent class or interface public abstract class A {public Stringfoo ="foo" ; }// Sub class public class A1extends A {public Stringbar ="bar" ; }// Apply it to a config @BeanConfig ( interfaces={ A.class } )This annotation can be used on the parent class so that it filters to all child classes, or can be set individually on the child classes.
Notes:
- The
@BeanType(interfaceClass)annotation is the equivalent annotation-based solution.
- Returns:
- The annotation value.
- Default:
- {}
- The
-
notBeanClasses
Class<?>[] notBeanClassesBean class exclusions.List of classes that should not be treated as beans even if they appear to be bean-like.
Not-bean classes are converted toStrings during serialization.Notes:
-
Supports VarResolver.DEFAULT (e.g.
"$C{myConfigVar}" ).
- Returns:
- The annotation value.
- Default:
- {}
-
Supports VarResolver.DEFAULT (e.g.
-
notBeanClasses_replace
Replace classes that should not be considered beans.Same as
notBeanClasses()but replaces any existing value.- Returns:
- The annotation value.
- Default:
- {}
-
notBeanPackages
Bean package exclusions.When specified, the current list of ignore packages are appended to.
Any classes within these packages will be serialized to strings using
Object.toString().Note that you can specify suffix patterns to include all subpackages.
Notes:
-
The default value excludes the following packages:
java.lang java.lang.annotation java.lang.ref java.lang.reflect java.io java.net java.nio.* java.util.*
-
Supports VarResolver.DEFAULT (e.g.
"$C{myConfigVar}" ).
- Returns:
- The annotation value.
- Default:
- {}
-
The default value excludes the following packages:
-
notBeanPackages_replace
Replace packages whose classes should not be considered beans.Same as
notBeanPackages()but replaces any existing value.- Returns:
- The annotation value.
- Default:
- {}
-
propertyNamer
Class<? extends PropertyNamer> propertyNamerBean property namer.The class to use for calculating bean property names.
Predefined classes:
BasicPropertyNamer(default)PropertyNamerDLC- Dashed-lower-case names.PropertyNamerULC- Dashed-upper-case names.
- Returns:
- The annotation value.
- Default:
- org.apache.juneau.commons.bean.PropertyNamer.Void.class
-
rank
int rankOptional rank for this config.Can be used to override default ordering and application of config annotations.
- Returns:
- The annotation value.
- Default:
- 0
-
unsortedProperties
Disable sorted bean properties.When
true , bean properties are serialized and accessed in declaration order instead of the default alphabetical order: record component order for records, field declaration order (superclass first) for other classes, then method-only properties alphabetically."true" "false" (default — properties are sorted alphabetically)
Notes:
-
Supports VarResolver.DEFAULT (e.g.
"$C{myConfigVar}" ).
- Returns:
- The annotation value.
- Default:
- ""
-
recordComponentOrder
Record component order.When
true , the properties ofRecordbeans use record component (declaration) order even when other beans are sorted alphabetically. Non-record beans are unaffected.Example:
@BeanConfig (recordComponentOrder="true" )public class MyRestResource { ... }public record Person(Stringname ,int age ) {}// Serialized as {"name":"Alice","age":30} instead of {"age":30,"name":"Alice"} "true" "false" (default: record properties are sorted alphabetically like other beans)
Notes:
-
Supports VarResolver.DEFAULT (e.g.
"$C{myConfigVar}" ).
- Returns:
- The annotation value.
- Default:
- ""
-
useJavaBeanIntrospector
Use Java Introspector.Using the built-in Java bean introspector will not pick up fields or non-standard getters/setters.
Most@BeanTypeannotations will be ignored."true" "false" (default)
Notes:
-
Supports VarResolver.DEFAULT (e.g.
"$C{myConfigVar}" ).
- Returns:
- The annotation value.
- Default:
- ""
-