public class BeanSession extends Session
Serializer
or Parser
.
This class is NOT thread safe. It is meant to be discarded after one-time use.
Modifier | Constructor and Description |
---|---|
protected |
BeanSession(BeanContext ctx,
BeanSessionArgs args)
Create a new session using properties specified in the context.
|
Modifier and Type | Method and Description |
---|---|
ClassMeta<Class> |
_class()
Returns a reusable
ClassMeta representation for the class |
void |
checkForWarnings()
Throws a
BeanRuntimeException if any warnings occurred in this session. |
<T> T |
convertToMemberType(Object outer,
Object value,
Class<T> type)
Same as
convertToType(Object, Class) , except used for instantiating inner member classes that must
be instantiated within another class instance. |
protected <T> T |
convertToMemberType(Object outer,
Object value,
ClassMeta<T> to)
Same as
convertToType(Object, ClassMeta) , except used for instantiating inner member classes that must
be instantiated within another class instance. |
<T> T |
convertToType(Object value,
Class<T> type)
Converts the specified value to the specified class type.
|
<T> T |
convertToType(Object value,
ClassMeta<T> type)
Casts the specified value into the specified type.
|
<T> T |
convertToType(Object value,
Type type,
Type... args)
Same as
convertToType(Object, Class) , but allows for complex data types consisting of collections or maps. |
protected ClassMeta<Object[]> |
getArgsClassMeta(Type[] classes)
|
protected Visibility |
getBeanClassVisibility()
Configuration property: Minimum bean class visibility.
|
protected Visibility |
getBeanConstructorVisibility()
Configuration property: Minimum bean constructor visibility.
|
protected List<Class<?>> |
getBeanDictionaryClasses()
Configuration property: Bean dictionary.
|
protected Visibility |
getBeanFieldVisibility()
Configuration property: Minimum bean field visibility.
|
protected BeanFilter[] |
getBeanFilters()
Configuration property: Bean filters.
|
<T> BeanMeta<T> |
getBeanMeta(Class<T> c)
Returns the
BeanMeta class for the specified class. |
protected Visibility |
getBeanMethodVisibility()
Configuration property: Minimum bean method visibility.
|
protected BeanRegistry |
getBeanRegistry()
Returns the bean registry defined in this bean context defined by
BeanContext.BEAN_beanDictionary . |
protected String |
getBeanTypePropertyName()
Configuration property: Bean type property name.
|
String |
getBeanTypePropertyName(ClassMeta cm)
Returns the type property name as defined by
BeanContext.BEAN_beanTypePropertyName . |
protected Map<String,Set<String>> |
getBpi()
Configuration property: Bean property includes.
|
protected Map<String,Set<String>> |
getBpro()
Configuration property: Read-only bean properties.
|
protected Map<String,Set<String>> |
getBpwo()
Configuration property: Write-only bean properties.
|
protected Map<String,Set<String>> |
getBpx()
Configuration property: Bean property excludes.
|
<T> ClassMeta<T> |
getClassMeta(Class<T> c)
Returns a
ClassMeta wrapper around a Class object. |
<T> ClassMeta<T> |
getClassMeta(Type type,
Type... args)
Used to resolve
|
protected ClassMeta<?> |
getClassMetaForObject(Object o,
ClassMeta<?> def)
Shortcut for calling
getClassMeta(o.getClass()) but returns a default value if object is |
<T> ClassMeta<T> |
getClassMetaForObject(T o)
Shortcut for calling
getClassMeta(o.getClass()) . |
protected Map<String,?> |
getExamples()
Configuration property: POJO examples.
|
protected Map<String,ClassInfo> |
getImplClasses()
Configuration property: Implementation classes.
|
Locale |
getLocale()
Configuration property: Locale.
|
MediaType |
getMediaType()
Configuration property: Media type.
|
protected Class<?>[] |
getNotBeanClasses()
Configuration property: Bean class exclusions.
|
protected String[] |
getNotBeanPackagesNames()
Configuration property: Bean package exclusions.
|
protected String[] |
getNotBeanPackagesPrefixes()
Configuration property: Bean package exclusions.
|
protected PojoSwap<?,?>[] |
getPojoSwaps()
Configuration property: POJO swaps.
|
protected PropertyNamer |
getPropertyNamer()
Configuration property: Bean property namer.
|
HttpPartSchema |
getSchema()
HTTP part schema of object being serialized or parsed.
|
protected StringBuilder |
getStringBuilder()
Creates a reusable
StringBuilder object from an internal pool. |
TimeZone |
getTimeZone()
Configuration property: Time zone.
|
ZoneId |
getTimeZoneId()
Configuration property: Time zone.
|
boolean |
isBean(Class<?> c)
Determines whether the specified class matches the requirements on this context of being a bean.
|
boolean |
isBean(Object o)
Determines whether the specified object matches the requirements on this context of being a bean.
|
protected boolean |
isBeanMapPutReturnsOldValue()
Configuration property: BeanMap.put() returns old property value.
|
protected boolean |
isBeansRequireDefaultConstructor()
Configuration property: Beans require no-arg constructors.
|
protected boolean |
isBeansRequireSerializable()
Configuration property: Beans require Serializable interface.
|
protected boolean |
isBeansRequireSettersForGetters()
Configuration property: Beans require setters for getters.
|
protected boolean |
isBeansRequireSomeProperties()
Configuration property: Beans require at least one property.
|
protected boolean |
isDebug()
Configuration property: Debug mode.
|
protected boolean |
isFluentSetters()
Configuration property: Find fluent setters.
|
protected boolean |
isIgnoreInvocationExceptionsOnGetters()
Configuration property: Ignore invocation errors on getters.
|
protected boolean |
isIgnoreInvocationExceptionsOnSetters()
Configuration property: Ignore invocation errors on setters.
|
protected boolean |
isIgnorePropertiesWithoutSetters()
Configuration property: Ignore properties without setters.
|
protected boolean |
isIgnoreUnknownBeanProperties()
Configuration property: Ignore unknown properties.
|
protected boolean |
isIgnoreUnknownNullBeanProperties()
Configuration property: Ignore unknown properties with null values.
|
protected boolean |
isSortProperties()
Configuration property: Sort bean properties.
|
protected boolean |
isUseEnumNames()
Configuration property: Use enum names.
|
protected boolean |
isUseInterfaceProxies()
Configuration property: Use interface proxies.
|
protected boolean |
isUseJavaBeanIntrospector()
Configuration property: Use Java Introspector.
|
<T> T |
newBean(Class<T> c)
Creates a new empty bean of the specified type, except used for instantiating inner member classes that must
be instantiated within another class instance.
|
<T> T |
newBean(Object outer,
Class<T> c)
Same as
newBean(Class) , except used for instantiating inner member classes that must be instantiated
within another class instance. |
<T> BeanMap<T> |
newBeanMap(Class<T> c)
|
<T> BeanMap<T> |
newBeanMap(Object outer,
Class<T> c)
Same as
newBeanMap(Class) , except used for instantiating inner member classes that must be instantiated
within another class instance. |
ClassMeta<Object> |
object()
Returns a reusable
ClassMeta representation for the class |
protected void |
returnStringBuilder(StringBuilder sb)
Returns a
StringBuilder object back into the internal reuse pool. |
ClassMeta<String> |
string()
Returns a reusable
ClassMeta representation for the class |
protected Object |
toArray(ClassMeta<?> type,
Collection<?> list)
Converts the contents of the specified list into an array.
|
<T> BeanMap<T> |
toBeanMap(T o)
|
<T> BeanMap<T> |
toBeanMap(T o,
Class<? super T> c)
|
ObjectMap |
toMap()
Returns the properties defined on this bean context as a simple map for debugging purposes.
|
addToCache, addToCache, addWarning, getClassProperty, getFromCache, getInstanceArrayProperty, getInstanceProperty, getLogger, getProperties, getProperty, getProperty, getProperty, getPropertyKeys, getWarnings, hasProperty, hasWarnings, toString
protected BeanSession(BeanContext ctx, BeanSessionArgs args)
ctx
- The context creating this session object.
The context contains all the configuration settings for this object.args
- Runtime session arguments.public final <T> T convertToType(Object value, Class<T> type) throws InvalidDataConversionException
See convertToType(Object, ClassMeta)
for the list of valid conversions.
T
- The class type to convert the value to.value
- The value to convert.type
- The class type to convert the value to.InvalidDataConversionException
- If the specified value cannot be converted to the specified type.public final <T> T convertToMemberType(Object outer, Object value, Class<T> type) throws InvalidDataConversionException
convertToType(Object, Class)
, except used for instantiating inner member classes that must
be instantiated within another class instance.T
- The class type to convert the value to.outer
- If class is a member class, this is the instance of the containing class.
Should be value
- The value to convert.type
- The class type to convert the value to.InvalidDataConversionException
- If the specified value cannot be converted to the specified type.public final <T> T convertToType(Object value, ClassMeta<T> type) throws InvalidDataConversionException
If the value isn't an instance of the specified type, then converts the value if possible.
The following conversions are valid:
Convert to type | Valid input value types | Notes |
---|---|---|
A class that is the normal type of a registered PojoSwap .
|
A value whose class matches the transformed type of that registered PojoSwap .
|
|
A class that is the transformed type of a registered PojoSwap .
|
A value whose class matches the normal type of that registered PojoSwap .
|
|
Number (e.g. Integer , Short , Float ,...)
Number. (e.g. Integer. ,
Short. , Float. ,...)
|
Number , String , |
For primitive TYPES , |
Map (e.g. Map , HashMap , TreeMap , ObjectMap )
|
Map
|
If Map is not constructible, a ObjectMap is created.
|
Collection (e.g. List , LinkedList , HashSet , ObjectList )
|
Collection<Object>
Object[]
|
If Collection is not constructible, a ObjectList is created.
|
X[] (array of any type X)
|
List<X>
|
|
X[][] (multi-dimensional arrays)
|
List<List<X>>
List<X[]>
List[]<X>
|
|
Enum
|
String
|
|
Bean |
Map
|
|
String
|
Anything | Arrays are converted to JSON arrays |
Anything with one of the following methods:
|
|
|
T
- The class type to convert the value to.value
- The value to be converted.type
- The target object type.InvalidDataConversionException
- If the specified value cannot be converted to the specified type.public final <T> T convertToType(Object value, Type type, Type... args) throws InvalidDataConversionException
convertToType(Object, Class)
, but allows for complex data types consisting of collections or maps.T
- The class type to convert the value to.value
- The value to be converted.type
- The target object type.args
- The target object parameter types.InvalidDataConversionException
- If the specified value cannot be converted to the specified type.protected final <T> T convertToMemberType(Object outer, Object value, ClassMeta<T> to) throws InvalidDataConversionException
convertToType(Object, ClassMeta)
, except used for instantiating inner member classes that must
be instantiated within another class instance.T
- The class type to convert the value to.outer
- If class is a member class, this is the instance of the containing class.
Should be value
- The value to convert.to
- The class type to convert the value to.InvalidDataConversionException
- If the specified value cannot be converted to the specified type.protected final Object toArray(ClassMeta<?> type, Collection<?> list)
Works on both object and primitive arrays.
In the case of multi-dimensional arrays, the incoming list must contain elements of type n-1 dimension.
i.e. if type
is
then list
must have entries of type
.
type
- The type to convert to. Must be an array type.list
- The contents to populate the array with.public final <T> BeanMap<T> toBeanMap(T o)
BeanMap
object (a modifiable Map
).
If object is not a true bean, then throws a BeanRuntimeException
with an explanation of why it's not a
bean.
T
- The class of the object being wrapped.o
- The object to wrap in a map interface. Must not be null.public final boolean isBean(Object o)
o
- The object being tested.public final boolean isBean(Class<?> c)
c
- The class being tested.public final <T> BeanMap<T> toBeanMap(T o, Class<? super T> c) throws BeanRuntimeException
BeanMap
object (i.e.: a modifiable Map
) defined as a bean for one of its
class, a super class, or an implemented interface.
If object is not a true bean, throws a BeanRuntimeException
with an explanation of why it's not a bean.
T
- The class of the object being wrapped.o
- The object to wrap in a bean interface. Must not be null.c
- The superclass to narrow the bean properties to. Must not be null.NullPointerException
- If either parameter is null.IllegalArgumentException
- If the specified object is not an an instance of the specified class.BeanRuntimeException
- If specified object is not a bean according to the bean rules specified in this context
class.public final <T> BeanMap<T> newBeanMap(Class<T> c)
BeanMap
object (a modifiable Map
) of the given class with uninitialized
property values.
If object is not a true bean, then throws a BeanRuntimeException
with an explanation of why it's not a
bean.
T
- The class of the object being wrapped.c
- The name of the class to create a new instance of.public final <T> BeanMap<T> newBeanMap(Object outer, Class<T> c)
newBeanMap(Class)
, except used for instantiating inner member classes that must be instantiated
within another class instance.T
- The class of the object being wrapped.c
- The name of the class to create a new instance of.outer
- If class is a member class, this is the instance of the containing class.
Should be public final <T> T newBean(Class<T> c) throws BeanRuntimeException
T
- The class type of the bean being created.c
- The class type of the bean being created.BeanRuntimeException
- If the specified class is not a valid bean.public final <T> T newBean(Object outer, Class<T> c) throws BeanRuntimeException
newBean(Class)
, except used for instantiating inner member classes that must be instantiated
within another class instance.T
- The class type of the bean being created.c
- The class type of the bean being created.outer
- If class is a member class, this is the instance of the containing class.
Should be BeanRuntimeException
- If the specified class is not a valid bean.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> c)
ClassMeta
wrapper around a Class
object.T
- The class type being wrapped.c
- The class being wrapped.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
protected final ClassMeta<Object[]> getArgsClassMeta(Type[] classes)
Type
objects, returns a ClassMeta
representing those arguments.
Constructs a new meta on each call.
classes
- The array of classes to get class metas for.ClassMeta
object corresponding to the classes. Never 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 ClassMeta<?> getClassMetaForObject(Object o, ClassMeta<?> def)
getClassMeta(o.getClass())
but returns a default value if object is o
- The class to find the class type for.def
- The default ClassMeta
if the object is null.o
is public final String getBeanTypePropertyName(ClassMeta cm)
BeanContext.BEAN_beanTypePropertyName
.cm
- The class meta of the type we're trying to resolve the type name for.
Can be protected final BeanRegistry getBeanRegistry()
BeanContext.BEAN_beanDictionary
.protected final StringBuilder getStringBuilder()
StringBuilder
object from an internal pool.
String builders are returned to the pool by calling returnStringBuilder(StringBuilder)
.
protected final void returnStringBuilder(StringBuilder sb)
StringBuilder
object back into the internal reuse pool.sb
- The string builder to return to the pool. No-op if public 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 public 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 public 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 Visibility getBeanClassVisibility()
BeanContext.BEAN_beanClassVisibility
protected final Visibility getBeanConstructorVisibility()
BeanContext.BEAN_beanConstructorVisibility
protected final List<Class<?>> getBeanDictionaryClasses()
BeanContext.BEAN_beanDictionary
protected final Visibility getBeanFieldVisibility()
BeanContext.BEAN_beanFieldVisibility
protected BeanFilter[] getBeanFilters()
BeanContext.BEAN_beanFilters
protected final boolean isBeanMapPutReturnsOldValue()
BeanMap.put()
method will return old property values.
BeanContext.BEAN_beanMapPutReturnsOldValue
protected final Visibility getBeanMethodVisibility()
BeanContext.BEAN_beanMethodVisibility
protected final boolean isBeansRequireDefaultConstructor()
Object.toString()
method.BeanContext.BEAN_beansRequireDefaultConstructor
protected final boolean isBeansRequireSerializable()
Serializable
interface to be considered a bean.
Object.toString()
method.BeanContext.BEAN_beansRequireSerializable
protected final boolean isBeansRequireSettersForGetters()
BeanContext.BEAN_beansRequireSettersForGetters
protected final boolean isBeansRequireSomeProperties()
Object.toString()
method.BeanContext.BEAN_beansRequireSomeProperties
protected final String getBeanTypePropertyName()
BeanContext.BEAN_beanTypePropertyName
protected final Map<String,Set<String>> getBpi()
BeanContext.BEAN_bpi
protected final Map<String,Set<String>> getBpx()
BeanContext.BEAN_bpx
protected final Map<String,Set<String>> getBpro()
BeanContext.BEAN_bpro
protected final Map<String,Set<String>> getBpwo()
BeanContext.BEAN_bpwo
protected final boolean isDebug()
BeanContext.BEAN_debug
protected final Map<String,?> getExamples()
BeanContext.BEAN_examples
protected final boolean isFluentSetters()
BeanContext.BEAN_fluentSetters
protected final boolean isIgnoreInvocationExceptionsOnGetters()
BeanContext.BEAN_ignoreInvocationExceptionsOnGetters
protected final boolean isIgnoreInvocationExceptionsOnSetters()
BeanContext.BEAN_ignoreInvocationExceptionsOnSetters
protected final boolean isIgnorePropertiesWithoutSetters()
RuntimeException
is thrown.BeanContext.BEAN_ignorePropertiesWithoutSetters
protected final boolean isIgnoreUnknownBeanProperties()
RuntimeException
is thrown.BeanContext.BEAN_ignoreUnknownBeanProperties
protected final boolean isIgnoreUnknownNullBeanProperties()
BeanContext.BEAN_ignoreUnknownNullBeanProperties
protected final Map<String,ClassInfo> getImplClasses()
BeanContext.BEAN_implClasses
public final Locale getLocale()
The locale is determined in the following order:
BeanContext.BEAN_locale
entry in parameter passed in through constructor.
BeanContext.BEAN_locale
setting on bean context.
Locale.getDefault()
.
BeanContext.BEAN_locale
public final MediaType getMediaType()
For example,
BeanContext.BEAN_mediaType
protected final Class<?>[] getNotBeanClasses()
BeanContext.BEAN_notBeanClasses
protected final String[] getNotBeanPackagesNames()
BeanContext.BEAN_notBeanPackages
protected final String[] getNotBeanPackagesPrefixes()
BeanContext.BEAN_notBeanPackages
protected final PojoSwap<?,?>[] getPojoSwaps()
BeanContext.BEAN_pojoSwaps
protected final PropertyNamer getPropertyNamer()
BeanContext.BEAN_propertyNamer
protected final boolean isSortProperties()
BeanContext.BEAN_sortProperties
public final TimeZone getTimeZone()
The timezone is determined in the following order:
BeanContext.BEAN_timeZone
entry in parameter passed in through constructor.
BeanContext.BEAN_timeZone
setting on bean context.
BeanContext.BEAN_timeZone
public final ZoneId getTimeZoneId()
The timezone is determined in the following order:
BeanContext.BEAN_timeZone
entry in parameter passed in through constructor.
BeanContext.BEAN_timeZone
setting on bean context.
BeanContext.BEAN_timeZone
protected final boolean isUseEnumNames()
Object.toString()
.BeanContext.BEAN_useEnumNames
protected final boolean isUseInterfaceProxies()
InvocationHandler
if there is no other way of instantiating them.BeanContext.BEAN_useInterfaceProxies
protected final boolean isUseJavaBeanIntrospector()
BeanContext.BEAN_useJavaBeanIntrospector
public final HttpPartSchema getSchema()
public void checkForWarnings()
Session
BeanRuntimeException
if any warnings occurred in this session.checkForWarnings
in class Session
Copyright © 2016–2019 The Apache Software Foundation. All rights reserved.