@ConfigurableContext public class BeanContext extends Context implements MetaProvider
This class servers multiple purposes:
Map
interfaces.
BeanFilters
,
PropertyNamers
, etc... which are used to tailor how POJOs are serialized and parsed.
All serializers and parsers extend from this context so that they can handle POJOs using a common framework.
BeanContext.create()
and BeanContextBuilder.build()
methods.
Each bean context maintains a cache of ClassMeta
objects that describe information about classes encountered.
These BeanContext
that share the same BeanContext
class cannot be overridden on the session.
BeanSession
objects are ephemeral and not thread-safe.
They are meant to be used as quickly-constructed scratchpads for creating bean maps.
BeanMap
objects can only be created through the session.
Some settings (e.g. BEAN_beansRequireDefaultConstructor
) are used to differentiate between bean
and non-bean classes.
Attempting to create a bean map around one of these objects will throw a BeanRuntimeException
.
The purpose for this behavior is so that the serializers can identify these non-bean classes and convert them to
plain strings using the Object.toString()
method.
Some settings (e.g. BEAN_beanFieldVisibility
) are used to determine what kinds of properties are
detected on beans.
Some settings (e.g. BEAN_beanMapPutReturnsOldValue
) change the runtime behavior of bean maps.
Settings are specified using the BeanContextBuilder.set(String, Object)
method and related convenience
methods.
BeanMaps
are wrappers around Java beans that allow properties to be retrieved and
set using the common Map.put(Object,Object)
and Map.get(Object)
methods.
Bean maps are created in two ways...
BeanSession.toBeanMap()
- Wraps an existing bean inside a Map
wrapper.
BeanSession.newBeanMap()
- Create a new bean instance wrapped in a
Map
wrapper.
Modifier and Type | Field and Description |
---|---|
static String |
BEAN_annotations
Configuration property: Annotations.
|
static String |
BEAN_beanClassVisibility
Configuration property: Minimum bean class visibility.
|
static String |
BEAN_beanConstructorVisibility
Configuration property: Minimum bean constructor visibility.
|
static String |
BEAN_beanDictionary
Configuration property: Bean dictionary.
|
static String |
BEAN_beanDictionary_add
Configuration property: Add to bean dictionary.
|
static String |
BEAN_beanDictionary_remove
Configuration property: Remove from bean dictionary.
|
static String |
BEAN_beanFieldVisibility
Configuration property: Minimum bean field visibility.
|
static String |
BEAN_beanFilters
Deprecated.
|
static String |
BEAN_beanFilters_add
Deprecated.
|
static String |
BEAN_beanFilters_remove
Deprecated.
|
static String |
BEAN_beanMapPutReturnsOldValue
Configuration property: BeanMap.put() returns old property value.
|
static String |
BEAN_beanMethodVisibility
Configuration property: Minimum bean method visibility.
|
static String |
BEAN_beansRequireDefaultConstructor
Configuration property: Beans require no-arg constructors.
|
static String |
BEAN_beansRequireSerializable
Configuration property: Beans require Serializable interface.
|
static String |
BEAN_beansRequireSettersForGetters
Configuration property: Beans require setters for getters.
|
static String |
BEAN_beansRequireSomeProperties
Configuration property: Beans require at least one property.
|
static String |
BEAN_bpi
Deprecated.
|
static String |
BEAN_bpro
Deprecated.
|
static String |
BEAN_bpwo
Deprecated.
|
static String |
BEAN_bpx
Deprecated.
|
static String |
BEAN_examples
Configuration property: POJO examples.
|
static String |
BEAN_excludeProperties
Deprecated.
|
static String |
BEAN_fluentSetters
Configuration property: Find fluent setters.
|
static String |
BEAN_ignoreInvocationExceptionsOnGetters
Configuration property: Ignore invocation errors on getters.
|
static String |
BEAN_ignoreInvocationExceptionsOnSetters
Configuration property: Ignore invocation errors on setters.
|
static String |
BEAN_ignorePropertiesWithoutSetters
Configuration property: Ignore properties without setters.
|
static String |
BEAN_ignoreTransientFields
Configuration property: Ignore transient fields.
|
static String |
BEAN_ignoreUnknownBeanProperties
Configuration property: Ignore unknown properties.
|
static String |
BEAN_ignoreUnknownNullBeanProperties
Configuration property: Ignore unknown properties with null values.
|
static String |
BEAN_implClasses
Configuration property: Implementation classes.
|
static String |
BEAN_includeProperties
Deprecated.
|
static String |
BEAN_notBeanClasses
Configuration property: Bean class exclusions.
|
static String |
BEAN_notBeanClasses_add
Configuration property: Add to classes that should not be considered beans.
|
static String |
BEAN_notBeanClasses_remove
Configuration property: Remove from classes that should not be considered beans.
|
static String |
BEAN_notBeanPackages
Configuration property: Bean package exclusions.
|
static String |
BEAN_notBeanPackages_add
Configuration property: Add to packages whose classes should not be considered beans.
|
static String |
BEAN_notBeanPackages_remove
Configuration property: Remove from packages whose classes should not be considered beans.
|
static String |
BEAN_pojoSwaps
Deprecated.
|
static String |
BEAN_pojoSwaps_add
Deprecated.
|
static String |
BEAN_pojoSwaps_remove
Deprecated.
|
static String |
BEAN_propertyNamer
Configuration property: Bean property namer.
|
static String |
BEAN_sortProperties
Configuration property: Sort bean properties.
|
static String |
BEAN_swaps
Configuration property: Java object swaps.
|
static String |
BEAN_swaps_add
Configuration property: Add to swap classes.
|
static String |
BEAN_swaps_remove
Configuration property: Remove from swap classes.
|
static String |
BEAN_typePropertyName
Configuration property: Bean type property name.
|
static String |
BEAN_useEnumNames
Configuration property: Use enum names.
|
static String |
BEAN_useInterfaceProxies
Configuration property: Use interface proxies.
|
static String |
BEAN_useJavaBeanIntrospector
Configuration property: Use Java Introspector.
|
static BeanContext |
DEFAULT
Default config.
|
static BeanContext |
DEFAULT_SORTED
Default config.
|
CONTEXT_debug, CONTEXT_locale, CONTEXT_mediaType, CONTEXT_timeZone
Constructor and Description |
---|
BeanContext(PropertyStore ps)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
protected ClassMeta<Class> |
_class()
Returns a reusable
ClassMeta representation for the class |
BeanContextBuilder |
builder()
Creates a builder from this context object.
|
static BeanContextBuilder |
create()
Instantiates a new clean-slate
BeanContextBuilder object. |
BeanSession |
createBeanSession()
Same as
createSession() except always returns a BeanSession object unlike createSession()
which is meant to be overridden by subclasses. |
BeanSession |
createBeanSession(BeanSessionArgs args)
Same as
createSession(BeanSessionArgs) except always returns a BeanSession object unlike createSession(BeanSessionArgs)
which is meant to be overridden by subclasses. |
BeanSessionArgs |
createDefaultBeanSessionArgs()
Same as
createDefaultSessionArgs() except always returns a BeanSessionArgs unlike
createDefaultBeanSessionArgs() which is meant to be overridden by subclasses. |
BeanSessionArgs |
createDefaultSessionArgs()
Defines default session arguments used when calling the
Context.createSession() method. |
BeanSession |
createSession()
Create a new bean session based on the properties defined on this context.
|
BeanSession |
createSession(BeanSessionArgs args)
Create a new bean session based on the properties defined on this context combined with the specified
runtime args.
|
Session |
createSession(SessionArgs args)
Create a new session based on the properties defined on this context combined with the specified
runtime args.
|
protected static void |
dumpCacheStats()
Prints meta cache statistics to
|
<A extends Annotation> |
getAnnotations(Class<A> a,
Class<?> c)
Finds the specified annotations on the specified class.
|
<A extends Annotation> |
getAnnotations(Class<A> a,
ClassInfo c)
Finds the specified annotations on the specified class.
|
<A extends Annotation> |
getAnnotations(Class<A> a,
Constructor<?> c)
Finds the specified annotations on the specified constructor.
|
<A extends Annotation> |
getAnnotations(Class<A> a,
ConstructorInfo c)
Finds the specified annotations on the specified constructor.
|
<A extends Annotation> |
getAnnotations(Class<A> a,
Field f)
Finds the specified annotations on the specified field.
|
<A extends Annotation> |
getAnnotations(Class<A> a,
FieldInfo f)
Finds the specified annotations on the specified field.
|
<A extends Annotation> |
getAnnotations(Class<A> a,
Method m)
Finds the specified annotations on the specified method.
|
<A extends Annotation> |
getAnnotations(Class<A> a,
MethodInfo m)
Finds the specified annotations on the specified method.
|
Visibility |
getBeanClassVisibility()
Minimum bean class visibility.
|
Visibility |
getBeanConstructorVisibility()
Minimum bean constructor visibility.
|
protected List<Class<?>> |
getBeanDictionaryClasses()
Bean dictionary.
|
Visibility |
getBeanFieldVisibility()
Minimum bean field visibility.
|
protected BeanFilter[] |
getBeanFilters()
Bean filters.
|
<T> BeanMeta<T> |
getBeanMeta(Class<T> c)
Returns the
BeanMeta class for the specified class. |
Visibility |
getBeanMethodVisibility()
Minimum bean method visibility.
|
protected BeanRegistry |
getBeanRegistry()
Returns the lookup table for resolving bean types by name.
|
protected WriterSerializer |
getBeanToStringSerializer()
Returns the serializer to use for serializing beans when using the
BeanSession.convertToType(Object, Class)
and related methods. |
protected String |
getBeanTypePropertyName()
Bean type property name.
|
protected Map<String,Set<String>> |
getBpi()
Bean property includes.
|
protected Set<String> |
getBpi(Class<?> c)
Returns the
BEAN_bpi setting for the specified class. |
protected Map<String,Set<String>> |
getBpro()
Read-only bean properties.
|
protected Set<String> |
getBpro(Class<?> c)
Returns the
BEAN_bpro setting for the specified class. |
protected Map<String,Set<String>> |
getBpwo()
Write-only bean properties.
|
protected Set<String> |
getBpwo(Class<?> c)
Returns the
BEAN_bpwo setting for the specified class. |
protected Map<String,Set<String>> |
getBpx()
Bean property excludes.
|
protected Set<String> |
getBpx(Class<?> c)
Returns the
BEAN_bpx setting for the specified class. |
<T> ClassMeta<T> |
getClassMeta(Class<T> type)
Construct a
ClassMeta wrapper around a Class object. |
<T> ClassMeta<T> |
getClassMeta(Type type,
Type... args)
Used to resolve
|
<T> ClassMeta<T> |
getClassMetaForObject(T o)
Shortcut for calling
getClassMeta(o.getClass()) . |
<A extends Annotation> |
getDeclaredAnnotations(Class<A> a,
Class<?> c)
Finds the specified declared annotations on the specified class.
|
<A extends Annotation> |
getDeclaredAnnotations(Class<A> a,
ClassInfo c)
Finds the specified declared annotation on the specified class.
|
protected Map<String,?> |
getExamples()
POJO examples.
|
protected <T> ConstructorInfo |
getImplClassConstructor(Class<T> c,
Visibility v)
Gets the no-arg constructor for the specified class.
|
protected Map<String,ClassInfo> |
getImplClasses()
Implementation classes.
|
<A extends Annotation> |
getLastAnnotation(Class<A> a,
Class<?> c)
Finds the last specified annotations on the specified class.
|
<A extends Annotation> |
getLastAnnotation(Class<A> a,
ClassInfo c)
Finds the last specified annotations on the specified class.
|
<A extends Annotation> |
getLastAnnotation(Class<A> a,
Constructor<?> c)
Finds the last specified annotations on the specified constructor.
|
<A extends Annotation> |
getLastAnnotation(Class<A> a,
ConstructorInfo c)
Finds the last specified annotations on the specified constructor.
|
<A extends Annotation> |
getLastAnnotation(Class<A> a,
Field f)
Finds the last specified annotations on the specified field.
|
<A extends Annotation> |
getLastAnnotation(Class<A> a,
FieldInfo f)
Finds the last specified annotations on the specified field.
|
<A extends Annotation> |
getLastAnnotation(Class<A> a,
Method m)
Finds the last specified annotations on the specified method.
|
<A extends Annotation> |
getLastAnnotation(Class<A> a,
MethodInfo m)
Finds the last specified annotations on the specified method.
|
<A extends Annotation> |
getLastDeclaredAnnotation(Class<A> a,
Class<?> c)
Finds the last specified declared annotations on the specified class.
|
<A extends Annotation> |
getLastDeclaredAnnotation(Class<A> a,
ClassInfo c)
Finds the last specified declared annotations on the specified class.
|
protected Class<?>[] |
getNotBeanClasses()
Bean class exclusions.
|
protected String[] |
getNotBeanPackagesNames()
Bean package exclusions.
|
protected String[] |
getNotBeanPackagesPrefixes()
Bean package exclusions.
|
protected PropertyNamer |
getPropertyNamer()
Bean property namer.
|
protected PojoSwap<?,?>[] |
getSwaps()
Java object swaps.
|
<A extends Annotation> |
hasAnnotation(Class<A> a,
Class<?> c)
Returns
|
<A extends Annotation> |
hasAnnotation(Class<A> a,
ClassInfo c)
Returns
|
<A extends Annotation> |
hasAnnotation(Class<A> a,
Constructor<?> c)
Returns
|
<A extends Annotation> |
hasAnnotation(Class<A> a,
ConstructorInfo c)
Returns
|
<A extends Annotation> |
hasAnnotation(Class<A> a,
Field f)
Returns
|
<A extends Annotation> |
hasAnnotation(Class<A> a,
FieldInfo f)
Returns
|
<A extends Annotation> |
hasAnnotation(Class<A> a,
Method m)
Returns
|
<A extends Annotation> |
hasAnnotation(Class<A> a,
MethodInfo m)
Returns
|
<A extends Annotation> |
hasDeclaredAnnotation(Class<A> a,
Class<?> c)
Returns
|
<A extends Annotation> |
hasDeclaredAnnotation(Class<A> a,
ClassInfo c)
Returns
|
boolean |
hasSameCache(BeanContext bc)
Returns
|
boolean |
isBean(Object o)
Returns
|
protected boolean |
isBeanMapPutReturnsOldValue()
BeanMap.put() returns old property value.
|
protected boolean |
isBeansRequireDefaultConstructor()
Beans require no-arg constructors.
|
protected boolean |
isBeansRequireSerializable()
Beans require Serializable interface.
|
protected boolean |
isBeansRequireSettersForGetters()
Beans require setters for getters.
|
protected boolean |
isBeansRequireSomeProperties()
Beans require at least one property.
|
protected boolean |
isFluentSetters()
Find fluent setters.
|
protected boolean |
isIgnoreInvocationExceptionsOnGetters()
Ignore invocation errors on getters.
|
protected boolean |
isIgnoreInvocationExceptionsOnSetters()
Ignore invocation errors on setters.
|
protected boolean |
isIgnorePropertiesWithoutSetters()
Ignore properties without setters.
|
protected boolean |
isIgnoreTransientFields()
Ignore transient fields.
|
protected boolean |
isIgnoreUnknownBeanProperties()
Ignore unknown properties.
|
protected boolean |
isIgnoreUnknownNullBeanProperties()
Ignore unknown properties with null values.
|
protected boolean |
isNotABean(Class<?> c)
Determines whether the specified class is ignored as a bean class based on the various exclusion parameters
specified on this context class.
|
protected boolean |
isSortProperties()
Sort bean properties.
|
protected boolean |
isUseEnumNames()
Use enum names.
|
protected boolean |
isUseInterfaceProxies()
Use interface proxies.
|
protected boolean |
isUseJavaBeanIntrospector()
Use Java Introspector.
|
protected ClassMeta<Object> |
object()
Returns a reusable
ClassMeta representation for the class |
protected <T> ClassMeta<T> |
resolveClassMeta(BeanProperty px,
Beanp p,
Type t,
Map<Class<?>,Class<?>[]> typeVarImpls)
Used for determining the class type on a method or field where a
@Beanp annotation may be present. |
protected ClassMeta<String> |
string()
Returns a reusable
ClassMeta representation for the class |
OMap |
toMap()
Returns the properties defined on this bean context as a simple map for debugging purposes.
|
equals, getArrayProperty, getArrayProperty, getBooleanProperty, getCdlProperty, getClassArrayProperty, getClassArrayProperty, getClassArrayProperty, getClassListProperty, getClassListProperty, getClassMapProperty, getClassMapProperty, getClassProperty, getClassSetProperty, getClassSetProperty, getDefaultLocale, getDefaultMediaType, getDefaultTimeZone, getInstanceArrayProperty, getInstanceArrayProperty, getInstanceArrayProperty, getInstanceProperty, getInstanceProperty, getInstanceProperty, getIntegerProperty, getListProperty, getListProperty, getLongProperty, getMapProperty, getProperty, getProperty, getPropertyKeys, getPropertyStore, getSetProperty, getSetProperty, getStringProperty, getStringPropertyWithNone, hashCode, identityCode, isDebug, toString
public static final String BEAN_annotations
BEAN_annotations
Annotation
>Defines annotations to apply to specific classes and methods.
Allows you to dynamically apply Juneau annotations typically applied directly to classes and methods. Useful in cases where you want to use the functionality of the annotation on beans and bean properties but do not have access to the code to do so.
As a rule, any Juneau annotation with an
The following example shows the equivalent methods for applying the @Bean
annotation:
In general, the underlying framework uses this method when it finds dynamically applied annotations on config annotations. However, concrete implementations of annotations are also provided that can be passed directly into builder classes like so:
The following is the list of concrete annotations provided that can be constructed and passed into the builder class:
BeanAnnotation
BeancAnnotation
BeanIgnoreAnnotation
BeanpAnnotation
ExampleAnnotation
NamePropertyAnnotation
ParentPropertyAnnotation
SwapAnnotation
UriAnnotation
CsvAnnotation
HtmlAnnotation
JsoAnnotation
JsonAnnotation
SchemaAnnotation
MsgPackAnnotation
OpenApiAnnotation
PlainTextAnnotation
SoapXmlAnnotation
UonAnnotation
UrlEncodingAnnotation
XmlAnnotation
The syntax for the
public static final String BEAN_beanClassVisibility
BEAN_beanClassVisibility
Visibility
Visibility.PUBLIC
Classes are not considered beans unless they meet the minimum visibility requirements.
For example, if the visibility is
@Bean
annotation can be used on a non-public bean class to override this setting.
@BeanIgnore
annotation can also be used on a public bean class to ignore it as a bean.
public static final String BEAN_beanConstructorVisibility
BEAN_beanConstructorVisibility
Visibility
Visibility.PUBLIC
Only look for constructors with the specified minimum visibility.
This setting affects the logic for finding no-arg constructors for bean. Normally, only
@Beanc
annotation can also be used to expose a non-public constructor.
@BeanIgnore
annotation can also be used on a public bean constructor to ignore it.
public static final String BEAN_beanDictionary
BEAN_beanDictionary
The list of classes that make up the bean dictionary in this bean context.
A dictionary is a name/class mapping used to find class types during parsing when they cannot be inferred
through reflection. The names are defined through the @Bean(typeName)
annotation defined
on the bean class. For example, if a class
This setting tells the parsers which classes to look for when resolving
Values can consist of any of the following types:
@Bean(typeName)
.
BeanDictionaryList
containing a collection of bean classes with type name annotations.
BeanDictionaryMap
containing a mapping of type names to classes without type name annotations.
Another option is to use the Bean.dictionary()
annotation on the POJO class itself:
A typical usage is to allow for HTML documents to be parsed back into HTML beans:
public static final String BEAN_beanDictionary_add
public static final String BEAN_beanDictionary_remove
public static final String BEAN_beanFieldVisibility
BEAN_beanFieldVisibility
Visibility
Visibility.PUBLIC
Only look for bean fields with the specified minimum visibility.
This affects which fields on a bean class are considered bean properties. Normally only
Bean fields can be ignored as properties entirely by setting the value to Visibility.NONE
@Beanp
annotation can also be used to expose a non-public field.
@BeanIgnore
annotation can also be used on a public bean field to ignore it as a bean property.
@Deprecated public static final String BEAN_beanFilters
BeanConfig.interfaces()
and other methods.
@Deprecated public static final String BEAN_beanFilters_add
BeanConfig.interfaces()
and other methods.
@Deprecated public static final String BEAN_beanFilters_remove
BeanConfig.interfaces()
and other methods.
public static final String BEAN_beanMapPutReturnsOldValue
BEAN_beanMapPutReturnsOldValue
When enabled, then the BeanMap.put()
method will return old property
values. Otherwise, it returns
Disabled by default because it introduces a slight performance penalty during serialization.
public static final String BEAN_beanMethodVisibility
BEAN_beanMethodVisibility
Visibility
Visibility.PUBLIC
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 only
@Beanp
annotation can also be used to expose a non-public method.
@BeanIgnore
annotation can also be used on a public bean getter/setter to ignore it as a bean property.
public static final String BEAN_beansRequireDefaultConstructor
BEAN_beansRequireDefaultConstructor
When enabled, 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 the Object.toString()
method.
@Bean
annotation can be used on a bean class to override this setting.
@BeanIgnore
annotation can also be used on a class to ignore it as a bean.
public static final String BEAN_beansRequireSerializable
BEAN_beansRequireSerializable
When enabled, a Java class must implement the Serializable
interface to be considered a bean.
Otherwise, the bean will be serialized as a string using the Object.toString()
method.
@Bean
annotation can be used on a bean class to override this setting.
@BeanIgnore
annotation can also be used on a class to ignore it as a bean.
public static final String BEAN_beansRequireSettersForGetters
BEAN_beansRequireSettersForGetters
When enabled, ignore read-only properties (properties with getters but not setters).
@Beanp
annotation can be used on the getter to override this setting.
@BeanIgnore
annotation can also be used on getters to ignore them as bean properties.
public static final String BEAN_beansRequireSomeProperties
BEAN_beansRequireSomeProperties
When enabled, then a Java class must contain at least 1 property to be considered a bean.
Otherwise, the bean will be serialized as a string using the Object.toString()
method.
The @Bean
annotation can be used on a class to override this setting when
@Bean
annotation can be used on the class to force it to be recognized as a bean class
even if it has no properties.
public static final String BEAN_typePropertyName
BEAN_typePropertyName
This specifies the name of the bean property used to store the dictionary name of a bean type so that the parser knows the data type to reconstruct.
@Deprecated public static final String BEAN_bpi
Bean.bpi()
and BeanConfig.bpi()
@Deprecated public static final String BEAN_bpx
Bean.bpx()
and BeanConfig.bpx()
@Deprecated public static final String BEAN_bpro
Bean.bpro()
and BeanConfig.bpro()
@Deprecated public static final String BEAN_bpwo
Bean.bpwo()
and BeanConfig.bpwo()
public static final String BEAN_examples
BEAN_examples
Specifies an example of the specified class.
Examples are used in cases such as POJO examples in Swagger documents.
Setting applies to specified class and all subclasses.
POJO examples can also be defined on classes via the following:
@Example
.
@Example
with zero arguments or one BeanSession
argument.
BeanSession
argument.
@Deprecated public static final String BEAN_excludeProperties
BEAN_bpx
public static final String BEAN_fluentSetters
BEAN_fluentSetters
When enabled, fluent setters are detected on beans during parsing.
Fluent setters must have the following attributes:
@Beanp
annotation can also be used on methods to individually identify them as fluent setters.
@Bean.fluentSetters()
annotation can also be used on classes to specify to look for fluent setters.
public static final String BEAN_ignoreInvocationExceptionsOnGetters
BEAN_ignoreInvocationExceptionsOnGetters
When enabled, errors thrown when calling bean getter methods will silently be ignored.
Otherwise, a BeanRuntimeException
is thrown.
public static final String BEAN_ignoreInvocationExceptionsOnSetters
BEAN_ignoreInvocationExceptionsOnSetters
When enabled, errors thrown when calling bean setter methods will silently be ignored.
Otherwise, a BeanRuntimeException
is thrown.
public static final String BEAN_ignorePropertiesWithoutSetters
BEAN_ignorePropertiesWithoutSetters
When enabled, trying to set a value on a bean property without a setter will silently be ignored.
Otherwise, a BeanRuntimeException
is thrown.
@BeanIgnore
annotation can also be used on getters and fields to ignore them.
public static final String BEAN_ignoreTransientFields
BEAN_ignoreTransientFields
When enabled, methods and fields marked as
@Beanp
annotation can also be used on transient fields to keep them from being ignored.
public static final String BEAN_ignoreUnknownBeanProperties
BEAN_ignoreUnknownBeanProperties
When enabled, trying to set a value on a non-existent bean property will silently be ignored.
Otherwise, a BeanRuntimeException
is thrown.
public static final String BEAN_ignoreUnknownNullBeanProperties
BEAN_ignoreUnknownNullBeanProperties
When enabled, trying to set a BeanRuntimeException
is thrown.
public static final String BEAN_implClasses
BEAN_implClasses
For interfaces and abstract classes this method can be used to specify an implementation class for the interface/abstract class so that instances of the implementation class are used when instantiated (e.g. during a parse).
@Deprecated public static final String BEAN_includeProperties
BEAN_bpi
public static final String BEAN_notBeanClasses
BEAN_notBeanClasses
List of classes that should not be treated as beans even if they appear to be bean-like.
Not-bean classes are converted to
Values can consist of any of the following types:
@BeanIgnore
annotation can also be used on classes to prevent them from being recognized as beans.
public static final String BEAN_notBeanClasses_add
public static final String BEAN_notBeanClasses_remove
public static final String BEAN_notBeanPackages
BEAN_notBeanPackages
Used as a convenient way of defining the BEAN_notBeanClasses
property for entire packages.
Any classes within these packages will be serialized to strings using Object.toString()
.
Note that you can specify suffix patterns to include all subpackages.
Values can consist of any of the following types:
public static final String BEAN_notBeanPackages_add
public static final String BEAN_notBeanPackages_remove
@Deprecated public static final String BEAN_pojoSwaps
BEAN_swaps
@Deprecated public static final String BEAN_pojoSwaps_add
BEAN_swaps_add
@Deprecated public static final String BEAN_pojoSwaps_remove
BEAN_swaps_remove
public static final String BEAN_propertyNamer
BEAN_propertyNamer
Class<PropertyNamer
>
PropertyNamerDefault
The class to use for calculating bean property names.
Predefined classes:
PropertyNamerDefault
- Default.
PropertyNamerDLC
- Dashed-lower-case names.
PropertyNamerULC
- Dashed-upper-case names.
public static final String BEAN_sortProperties
BEAN_sortProperties
When enabled, all bean properties will be serialized and access in alphabetical order. Otherwise, the natural order of the bean properties is used which is dependent on the JVM vendor. On IBM JVMs, the bean properties are ordered based on their ordering in the Java file. On Oracle JVMs, the bean properties are not ordered (which follows the official JVM specs).
This property is disabled by default so that IBM JVM users don't have to use @Bean
annotations
to force bean properties to be in a particular order and can just alter the order of the fields/methods
in the Java file.
@Bean.sort()
annotation can also be used to sort properties on just a single class.
public static final String BEAN_swaps
BEAN_swaps
Swaps are used to "swap out" non-serializable classes with serializable equivalents during serialization, and "swap in" the non-serializable class during parsing.
An example of a swap would be a
Multiple swaps can be associated with a single class.
When multiple swaps are applicable to the same class, the media type pattern defined by
PojoSwap.forMediaTypes()
or @Swap(mediaTypes)
are used to come up with the best match.
Values can consist of any of the following types:
PojoSwap
.
PojoSwap
.
SurrogateSwap
.
@Swap
annotation can also be used on classes to identify swaps for the class.
@Swap
annotation can also be used on bean methods and fields to identify swaps for values of those bean properties.
public static final String BEAN_swaps_add
public static final String BEAN_swaps_remove
public static final String BEAN_useEnumNames
BEAN_useEnumNames
When enabled, enums are always serialized by name, not using Object.toString()
.
public static final String BEAN_useInterfaceProxies
BEAN_useInterfaceProxies
When enabled, interfaces will be instantiated as proxy classes through the use of an
InvocationHandler
if there is no other way of instantiating them.
Otherwise, throws a BeanRuntimeException
.
public static final String BEAN_useJavaBeanIntrospector
BEAN_useJavaBeanIntrospector
Using the built-in Java bean introspector will not pick up fields or non-standard getters/setters.
Most @Bean
annotations will be ignored.
public static final BeanContext DEFAULT
public static final BeanContext DEFAULT_SORTED
public BeanContext(PropertyStore ps)
Typically only called from ContextBuilder.build(Class)
method.
ps
- The property store containing the unmodifiable configuration for this bean context.public BeanContextBuilder builder()
Context
Builders are used to define new contexts (e.g. serializers, parsers) based on existing configurations.
public static BeanContextBuilder create()
BeanContextBuilder
object.
This is equivalent to simply calling
.
JsonSerializerBuilder
object.public BeanSession createSession()
Use this method for creating sessions if you don't need to override any properties or locale/timezone currently set on this context.
createSession
in class Context
public BeanSession createSession(BeanSessionArgs args)
Use this method for creating sessions if you don't need to override any properties or locale/timezone currently set on this context.
args
- The session arguments.public final Session createSession(SessionArgs args)
Context
Use this method for creating sessions if you don't need to override any properties or locale/timezone currently set on this context.
createSession
in class Context
args
- The session arguments.public final BeanSession createBeanSession(BeanSessionArgs args)
createSession(BeanSessionArgs)
except always returns a BeanSession
object unlike createSession(BeanSessionArgs)
which is meant to be overridden by subclasses.args
- The session arguments.public final BeanSession createBeanSession()
createSession()
except always returns a BeanSession
object unlike createSession()
which is meant to be overridden by subclasses.public BeanSessionArgs createDefaultSessionArgs()
Context
Context.createSession()
method.createDefaultSessionArgs
in class Context
public final BeanSessionArgs createDefaultBeanSessionArgs()
createDefaultSessionArgs()
except always returns a BeanSessionArgs
unlike
createDefaultBeanSessionArgs()
which is meant to be overridden by subclasses.public final boolean hasSameCache(BeanContext bc)
Useful for testing purposes.
bc
- The bean context to compare to.protected final boolean isNotABean(Class<?> c)
c
- The class type being tested.public boolean isBean(Object o)
o
- The object to test.protected static void dumpCacheStats()
public final <T> BeanMeta<T> getBeanMeta(Class<T> c)
BeanMeta
class for the specified class.T
- The class type to get the meta-data on.c
- The class to get the meta-data on.BeanMeta
for the specified class, or public final <T> ClassMeta<T> getClassMeta(Class<T> type)
ClassMeta
wrapper around a Class
object.public final <T> ClassMeta<T> getClassMeta(Type type, Type... args)
The array can be arbitrarily long to indicate arbitrarily complex data structures.
getClassMeta(String.class );
- A normal type.
getClassMeta(List.class );
- A list containing objects.
getClassMeta(List.class , String.class );
- A list containing strings.
getClassMeta(LinkedList.class , String.class );
- A linked-list containing
strings.
getClassMeta(LinkedList.class , LinkedList.class , String.class );
-
A linked-list containing linked-lists of strings.
getClassMeta(Map.class );
- A map containing object keys/values.
getClassMeta(Map.class , String.class , String.class );
- A map
containing string keys/values.
getClassMeta(Map.class , String.class , List.class , MyBean.class );
-
A map containing string keys and values of lists containing beans.
type
- The class to resolve.
ClassMeta
, Class
, ParameterizedType
, GenericArrayType
args
- The type arguments of the class if it's a collection or map.
ClassMeta
, Class
, ParameterizedType
, GenericArrayType
public final <T> ClassMeta<T> getClassMetaForObject(T o)
getClassMeta(o.getClass())
.T
- The class of the object being passed in.o
- The class to find the class type for.o
is protected final <T> ClassMeta<T> resolveClassMeta(BeanProperty px, Beanp p, Type t, Map<Class<?>,Class<?>[]> typeVarImpls)
@Beanp
annotation may be present.T
- The class type we're wrapping.px
- The property annotation on the type if there is one.p
- The property annotation on the type if there is one.t
- The type.typeVarImpls
- Contains known resolved type parameters on the specified class so that we can result
ParameterizedTypes
and TypeVariables
.
Can be ClassMeta
object wrapped around the Type
object.protected final <T> ConstructorInfo getImplClassConstructor(Class<T> c, Visibility v)
T
- The class to check.c
- The class to check.v
- The minimum visibility for the constructor.protected final ClassMeta<Object> object()
ClassMeta
representation for the class
This
This method is identical to calling getClassMeta(Object.
but uses a cached copy to
avoid a hashmap lookup.
ClassMeta
object associated with the protected final ClassMeta<String> string()
ClassMeta
representation for the class
This
This method is identical to calling getClassMeta(String.
but uses a cached copy to
avoid a hashmap lookup.
ClassMeta
object associated with the protected final ClassMeta<Class> _class()
ClassMeta
representation for the class
This
This method is identical to calling getClassMeta(Class.
but uses a cached copy to
avoid a hashmap lookup.
ClassMeta
object associated with the protected final BeanRegistry getBeanRegistry()
public <A extends Annotation> List<A> getAnnotations(Class<A> a, Class<?> c)
getAnnotations
in interface MetaProvider
A
- The annotation type to find.a
- The annotation type to find.c
- The class to search on.public <A extends Annotation> List<A> getAnnotations(Class<A> a, ClassInfo c)
A
- The annotation type to find.a
- The annotation type to find.c
- The class to search on.public <A extends Annotation> A getLastAnnotation(Class<A> a, Class<?> c)
A
- The annotation type to find.a
- The annotation type to find.c
- The class to search on.public <A extends Annotation> A getLastAnnotation(Class<A> a, ClassInfo c)
A
- The annotation type to find.a
- The annotation type to find.c
- The class to search on.public <A extends Annotation> List<A> getDeclaredAnnotations(Class<A> a, Class<?> c)
getDeclaredAnnotations
in interface MetaProvider
A
- The annotation type to find.a
- The annotation type to find.c
- The class to search on.public <A extends Annotation> List<A> getDeclaredAnnotations(Class<A> a, ClassInfo c)
A
- The annotation type to find.a
- The annotation type to find.c
- The class to search on.public <A extends Annotation> A getLastDeclaredAnnotation(Class<A> a, Class<?> c)
A
- The annotation type to find.a
- The annotation type to find.c
- The class to search on.public <A extends Annotation> A getLastDeclaredAnnotation(Class<A> a, ClassInfo c)
A
- The annotation type to find.a
- The annotation type to find.c
- The class to search on.public <A extends Annotation> List<A> getAnnotations(Class<A> a, Method m)
getAnnotations
in interface MetaProvider
A
- The annotation type to find.a
- The annotation type to find.m
- The method to search on.public <A extends Annotation> List<A> getAnnotations(Class<A> a, MethodInfo m)
A
- The annotation type to find.a
- The annotation type to find.m
- The method to search on.public <A extends Annotation> A getLastAnnotation(Class<A> a, Method m)
A
- The annotation type to find.a
- The annotation type to find.m
- The method to search on.public <A extends Annotation> A getLastAnnotation(Class<A> a, MethodInfo m)
A
- The annotation type to find.a
- The annotation type to find.m
- The method to search on.public <A extends Annotation> List<A> getAnnotations(Class<A> a, Field f)
getAnnotations
in interface MetaProvider
A
- The annotation type to find.a
- The annotation type to find.f
- The field to search on.public <A extends Annotation> List<A> getAnnotations(Class<A> a, FieldInfo f)
A
- The annotation type to find.a
- The annotation type to find.f
- The field to search on.public <A extends Annotation> A getLastAnnotation(Class<A> a, Field f)
A
- The annotation type to find.a
- The annotation type to find.f
- The field to search on.public <A extends Annotation> A getLastAnnotation(Class<A> a, FieldInfo f)
A
- The annotation type to find.a
- The annotation type to find.f
- The field to search on.public <A extends Annotation> List<A> getAnnotations(Class<A> a, Constructor<?> c)
getAnnotations
in interface MetaProvider
A
- The annotation type to find.a
- The annotation type to find.c
- The constructor to search on.public <A extends Annotation> List<A> getAnnotations(Class<A> a, ConstructorInfo c)
A
- The annotation type to find.a
- The annotation type to find.c
- The constructor to search on.public <A extends Annotation> A getLastAnnotation(Class<A> a, Constructor<?> c)
A
- The annotation type to find.a
- The annotation type to find.c
- The constructor to search on.public <A extends Annotation> A getLastAnnotation(Class<A> a, ConstructorInfo c)
A
- The annotation type to find.a
- The annotation type to find.c
- The constructor to search on.public <A extends Annotation> boolean hasAnnotation(Class<A> a, Class<?> c)
a
- The annotation being checked for.c
- The class being checked on.public <A extends Annotation> boolean hasAnnotation(Class<A> a, ClassInfo c)
a
- The annotation being checked for.c
- The class being checked on.public <A extends Annotation> boolean hasDeclaredAnnotation(Class<A> a, Class<?> c)
a
- The annotation being checked for.c
- The class being checked on.public <A extends Annotation> boolean hasDeclaredAnnotation(Class<A> a, ClassInfo c)
a
- The annotation being checked for.c
- The class being checked on.public <A extends Annotation> boolean hasAnnotation(Class<A> a, Method m)
a
- The annotation being checked for.m
- The method being checked on.public <A extends Annotation> boolean hasAnnotation(Class<A> a, MethodInfo m)
a
- The annotation being checked for.m
- The method being checked on.public <A extends Annotation> boolean hasAnnotation(Class<A> a, Field f)
a
- The annotation being checked for.f
- The field being checked on.public <A extends Annotation> boolean hasAnnotation(Class<A> a, FieldInfo f)
a
- The annotation being checked for.f
- The field being checked on.public <A extends Annotation> boolean hasAnnotation(Class<A> a, Constructor<?> c)
a
- The annotation being checked for.c
- The constructor being checked on.public <A extends Annotation> boolean hasAnnotation(Class<A> a, ConstructorInfo c)
a
- The annotation being checked for.c
- The constructor being checked on.public final Visibility getBeanClassVisibility()
BEAN_beanClassVisibility
public final Visibility getBeanConstructorVisibility()
BEAN_beanConstructorVisibility
protected final List<Class<?>> getBeanDictionaryClasses()
BEAN_beanDictionary
public final Visibility getBeanFieldVisibility()
BEAN_beanFieldVisibility
protected final BeanFilter[] getBeanFilters()
BEAN_beanFilters
protected final boolean isBeanMapPutReturnsOldValue()
BeanMap.put()
method will return old property values.
BEAN_beanMapPutReturnsOldValue
public final Visibility getBeanMethodVisibility()
BEAN_beanMethodVisibility
protected final boolean isBeansRequireDefaultConstructor()
Object.toString()
method.BEAN_beansRequireDefaultConstructor
protected final boolean isBeansRequireSerializable()
Serializable
interface to be considered a bean.
Object.toString()
method.BEAN_beansRequireSerializable
protected final boolean isBeansRequireSettersForGetters()
BEAN_beansRequireSettersForGetters
protected final boolean isBeansRequireSomeProperties()
Object.toString()
method.BEAN_beansRequireSomeProperties
protected final String getBeanTypePropertyName()
BEAN_typePropertyName
protected final Map<String,Set<String>> getBpi()
BEAN_bpi
protected Set<String> getBpi(Class<?> c)
BEAN_bpi
setting for the specified class.c
- The class.protected final Map<String,Set<String>> getBpx()
BEAN_bpx
protected Set<String> getBpx(Class<?> c)
BEAN_bpx
setting for the specified class.c
- The class.protected final Map<String,Set<String>> getBpro()
BEAN_bpro
protected Set<String> getBpro(Class<?> c)
BEAN_bpro
setting for the specified class.c
- The class.protected final Map<String,Set<String>> getBpwo()
BEAN_bpwo
protected Set<String> getBpwo(Class<?> c)
BEAN_bpwo
setting for the specified class.c
- The class.protected final Map<String,?> getExamples()
BEAN_examples
protected final boolean isFluentSetters()
BEAN_fluentSetters
protected final boolean isIgnoreInvocationExceptionsOnGetters()
BEAN_ignoreInvocationExceptionsOnGetters
protected final boolean isIgnoreInvocationExceptionsOnSetters()
BEAN_ignoreInvocationExceptionsOnSetters
protected final boolean isIgnorePropertiesWithoutSetters()
BEAN_ignorePropertiesWithoutSetters
protected final boolean isIgnoreTransientFields()
BEAN_ignoreTransientFields
protected final boolean isIgnoreUnknownBeanProperties()
RuntimeException
is thrown.BEAN_ignoreUnknownBeanProperties
protected final boolean isIgnoreUnknownNullBeanProperties()
BEAN_ignoreUnknownNullBeanProperties
protected final Map<String,ClassInfo> getImplClasses()
BEAN_implClasses
protected final Class<?>[] getNotBeanClasses()
BEAN_notBeanClasses
protected final String[] getNotBeanPackagesNames()
BEAN_notBeanPackages
protected final String[] getNotBeanPackagesPrefixes()
BEAN_notBeanPackages
protected final PojoSwap<?,?>[] getSwaps()
BEAN_swaps
protected final PropertyNamer getPropertyNamer()
BEAN_propertyNamer
protected final boolean isSortProperties()
BEAN_sortProperties
protected final boolean isUseEnumNames()
Object.toString()
.BEAN_useEnumNames
protected final boolean isUseInterfaceProxies()
InvocationHandler
if there is no other way of instantiating them.BEAN_useInterfaceProxies
protected final boolean isUseJavaBeanIntrospector()
BEAN_useJavaBeanIntrospector
protected WriterSerializer getBeanToStringSerializer()
BeanSession.convertToType(Object, Class)
and related methods.Copyright © 2016–2020 The Apache Software Foundation. All rights reserved.