Class BeanSession
- Direct Known Subclasses:
- BeanTraverseSession,- ParserSession,- RestRequest
BeanContext.
 - Typically session objects are not thread safe nor reusable. However, bean sessions do not maintain any state and thus can be safely cached and reused.
See Also:
- 
Nested Class SummaryNested Classes
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescription_class()Returns a reusableClassMetarepresentation for the classClass .voidaddWarning(String msg, Object... args) Logs a warning message.final <T> TconvertToMemberType(Object outer, Object value, Class<T> type) Same asconvertToType(Object, Class), except used for instantiating inner member classes that must be instantiated within another class instance.protected final <T> TconvertToMemberType(Object outer, Object value, ClassMeta<T> to) Same asconvertToType(Object, ClassMeta), except used for instantiating inner member classes that must be instantiated within another class instance.final <T> TconvertToType(Object value, Class<T> type) Converts the specified value to the specified class type.final <T> TconvertToType(Object value, Type type, Type... args) Same asconvertToType(Object, Class), but allows for complex data types consisting of collections or maps.final <T> TconvertToType(Object value, ClassMeta<T> type) Casts the specified value into the specified type.static BeanSession.Buildercreate(BeanContext ctx) Creates a builder of this object.getArgsClassMeta(Type[] classes) final VisibilityMinimum bean class visibility.final VisibilityMinimum bean constructor visibility.Bean dictionary.final VisibilityMinimum bean field visibility.final <T> BeanMeta<T>getBeanMeta(Class<T> c) Returns theBeanMetaclass for the specified class.final VisibilityMinimum bean method visibility.final BeanRegistryReturns the bean registry defined in this bean context defined byBeanContext.Builder.beanDictionary(Class...).final StringBean type property name.final StringReturns the type property name as defined byBeanContext.Builder.typePropertyName(String).final <T> ClassMeta<T>getClassMeta(Class<T> c) Returns aClassMetawrapper around aClassobject.final <T> ClassMeta<T>getClassMeta(Type type, Type... args) Used to resolveClassMetas of typeCollection andMap that haveClassMeta values that themselves could be collections or maps.protected final ClassMeta<?>getClassMetaForObject(Object o, ClassMeta<?> def) Shortcut for callinggetClassMeta(o.getClass())but returns a default value if object isnull .final <T> ClassMeta<T>Shortcut for callinggetClassMeta(o.getClass()).Locale.final MediaTypeMedia type.final StringReturns the name property name.final Class<?>[]Bean class exclusions.final String[]Bean package exclusions.protected final String[]Bean package exclusions.final PropertyNamerBean property namer.final ObjectSwap<?,?>[] getSwaps()Java object swaps.final TimeZoneTime zone.final ZoneIdTime zone.final booleanDetermines whether the specified class matches the requirements on this context of being a bean.final booleanDetermines whether the specified object matches the requirements on this context of being a bean.final booleanBeanMap.put() returns old property value.final booleanBeans require no-arg constructors.final booleanBeans require Serializable interface.final booleanBeans require setters for getters.final booleanBeans require at least one property.final booleanFind fluent setters.final booleanIgnore invocation errors on getters.final booleanIgnore invocation errors on setters.final booleanSilently ignore missing setters.final booleanIgnore unknown properties.final booleanIgnore unknown properties with null values.final booleanSort bean properties.final booleanUse enum names.final booleanUse interface proxies.final booleanUse Java Introspector.final <T> TCreates a new empty bean of the specified type, except used for instantiating inner member classes that must be instantiated within another class instance.final <T> TSame asnewBean(Class), except used for instantiating inner member classes that must be instantiated within another class instance.final <T> BeanMap<T>newBeanMap(Class<T> c) final <T> BeanMap<T>newBeanMap(Object outer, Class<T> c) Same asnewBeanMap(Class), except used for instantiating inner member classes that must be instantiated within another class instance.protected MapnewGenericMap(ClassMeta mapMeta) Creates either anJsonMaporLinkedHashMapdepending on whether the key type is String or something else.object()Returns a reusableClassMetarepresentation for the classObject .string()Returns a reusableClassMetarepresentation for the classString .protected final ObjecttoArray(ClassMeta<?> type, Collection<?> list) Converts the contents of the specified list into an array.final <T> BeanMap<T>toBeanMap(T o) final <T> BeanMap<T>final <T> BeanMap<T>toBeanMap(T o, PropertyNamer propertyNamer) Methods inherited from class org.apache.juneau.ContextSessioncheckForWarnings, getContext, getSessionProperties, getWarnings, isDebug, properties, toString
- 
Constructor Details- 
BeanSessionConstructor.- Parameters:
- builder- The builder for this object.
 
 
- 
- 
Method Details- 
createCreates a builder of this object.- Parameters:
- ctx- The context creating this builder.
- Returns:
- A new builder.
 
- 
convertToTypeConverts the specified value to the specified class type.See convertToType(Object, ClassMeta)for the list of valid conversions.- Type Parameters:
- T- The class type to convert the value to.
- Parameters:
- value- The value to convert.
- type- The class type to convert the value to.
- Returns:
- The converted value.
- Throws:
- InvalidDataConversionException- If the specified value cannot be converted to the specified type.
 
- 
convertToMemberTypepublic final <T> T convertToMemberType(Object outer, Object value, Class<T> type) throws InvalidDataConversionException Same asconvertToType(Object, Class), except used for instantiating inner member classes that must be instantiated within another class instance.- Type Parameters:
- T- The class type to convert the value to.
- Parameters:
- outer- If class is a member class, this is the instance of the containing class. Should be- null if not a member class.
- value- The value to convert.
- type- The class type to convert the value to.
- Returns:
- The converted value.
- Throws:
- InvalidDataConversionException- If the specified value cannot be converted to the specified type.
 
- 
convertToTypepublic final <T> T convertToType(Object value, ClassMeta<T> type) throws InvalidDataConversionException Casts the specified value into the specified type.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 ObjectSwap.A value whose class matches the transformed type of that registered ObjectSwap.A class that is the transformed type of a registered ObjectSwap.A value whose class matches the normal type of that registered ObjectSwap.Number(e.g.Integer,Short,Float,...)Number.(e.g.TYPE Integer.,TYPE Short.,TYPE Float.,...)TYPE Number,String,null For primitive TYPES,null returns the JVM default value for that type.Map(e.g.Map,HashMap,TreeMap,JsonMap)MapIf Mapis not constructible, anJsonMapis created.Collection(e.g.List,LinkedList,HashSet,JsonList)Collection<Object>Object[]If Collectionis not constructible, anJsonListis created.X[](array of any type X)List<X>X[][](multi-dimensional arrays)List<List<X>>List<X[]>List[]<X>EnumStringBean MapStringAnything Arrays are converted to JSON arrays Anything with one of the following methods: public static T fromString(String)public static T valueOf(String)public T(String)String 
 - Type Parameters:
- T- The class type to convert the value to.
- Parameters:
- value- The value to be converted.
- type- The target object type.
- Returns:
- The converted type.
- Throws:
- InvalidDataConversionException- If the specified value cannot be converted to the specified type.
 
- 
convertToTypepublic final <T> T convertToType(Object value, Type type, Type... args) throws InvalidDataConversionException Same asconvertToType(Object, Class), but allows for complex data types consisting of collections or maps.- Type Parameters:
- T- The class type to convert the value to.
- Parameters:
- value- The value to be converted.
- type- The target object type.
- args- The target object parameter types.
- Returns:
- The converted type.
- Throws:
- InvalidDataConversionException- If the specified value cannot be converted to the specified type.
 
- 
convertToMemberTypeprotected final <T> T convertToMemberType(Object outer, Object value, ClassMeta<T> to) throws InvalidDataConversionException Same asconvertToType(Object, ClassMeta), except used for instantiating inner member classes that must be instantiated within another class instance.- Type Parameters:
- T- The class type to convert the value to.
- Parameters:
- outer- If class is a member class, this is the instance of the containing class. Should be- null if not a member class.
- value- The value to convert.
- to- The class type to convert the value to.
- Returns:
- The converted value.
- Throws:
- InvalidDataConversionException- If the specified value cannot be converted to the specified type.
 
- 
toArrayConverts the contents of the specified list into an array.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 typeisint [][]listmust have entries of typeint []- Parameters:
- type- The type to convert to. Must be an array type.
- list- The contents to populate the array with.
- Returns:
- A new object or primitive array.
 
- 
toBeanMapWraps an object inside aBeanMapobject (a modifiableMap).If object is not a true bean, then throws a BeanRuntimeExceptionwith an explanation of why it's not a bean.If object is already a BeanMap, simply returns the same object.Example:// Construct a bean map around a bean instance BeanMap<Person>beanMap = BeanContext.DEFAULT .toBeanMap(new Person());- Type Parameters:
- T- The class of the object being wrapped.
- Parameters:
- o- The object to wrap in a map interface. Must not be null.
- Returns:
- The wrapped object.
 
- 
toBeanMapWraps an object inside aBeanMapobject (a modifiableMap).Same as toBeanMap(Object)but allows you to specify a property namer instance.Example:// Construct a bean map around a bean instance BeanMap<Person>beanMap = BeanContext.DEFAULT .toBeanMap(new Person(), PropertyNamerDLC.INSTANCE );- Type Parameters:
- T- The class of the object being wrapped.
- Parameters:
- o- The object to wrap in a map interface. Must not be null.
- propertyNamer- The property namer to use.
- Returns:
- The wrapped object.
 
- 
isBeanDetermines whether the specified object matches the requirements on this context of being a bean.- Parameters:
- o- The object being tested.
- Returns:
- true if the specified object is considered a bean.
 
- 
isBeanDetermines whether the specified class matches the requirements on this context of being a bean.- Parameters:
- c- The class being tested.
- Returns:
- true if the specified class is considered a bean.
 
- 
toBeanMapWraps an object inside aBeanMapobject (i.e.: a modifiableMap) 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 BeanRuntimeExceptionwith an explanation of why it's not a bean.Example:// Construct a bean map for new bean using only properties defined in a superclass BeanMap<MySubBean>beanMap = BeanContext.DEFAULT .toBeanMap(new MySubBean(), MySuperBean.class );// Construct a bean map for new bean using only properties defined in an interface BeanMap<MySubBean>beanMap = BeanContext.DEFAULT .toBeanMap(new MySubBean(), MySuperInterface.class );- Type Parameters:
- T- The class of the object being wrapped.
- Parameters:
- 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.
- Returns:
- The bean representation, or null if the object is not a true bean.
- Throws:
- 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.
 
- 
newBeanMapCreates a newBeanMapobject (a modifiableMap) of the given class with uninitialized property values.If object is not a true bean, then throws a BeanRuntimeExceptionwith an explanation of why it's not a bean.Example:// Construct a new bean map wrapped around a new Person object BeanMap<Person>beanMap = BeanContext.DEFAULT .newBeanMap(Person.class );- Type Parameters:
- T- The class of the object being wrapped.
- Parameters:
- c- The name of the class to create a new instance of.
- Returns:
- A new instance of the class.
 
- 
newBeanMapSame asnewBeanMap(Class), except used for instantiating inner member classes that must be instantiated within another class instance.- Type Parameters:
- T- The class of the object being wrapped.
- Parameters:
- 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- null if not a member class.
- Returns:
- A new instance of the class.
 
- 
newBeanCreates a new empty bean of the specified type, except used for instantiating inner member classes that must be instantiated within another class instance.Example:// Construct a new instance of the specified bean class Personperson = BeanContext.DEFAULT .newBean(Person.class );- Type Parameters:
- T- The class type of the bean being created.
- Parameters:
- c- The class type of the bean being created.
- Returns:
- A new bean object.
- Throws:
- BeanRuntimeException- If the specified class is not a valid bean.
 
- 
newBeanSame asnewBean(Class), except used for instantiating inner member classes that must be instantiated within another class instance.- Type Parameters:
- T- The class type of the bean being created.
- Parameters:
- 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- null if not a member class.
- Returns:
- A new bean object.
- Throws:
- BeanRuntimeException- If the specified class is not a valid bean.
 
- 
getBeanMetaReturns theBeanMetaclass for the specified class.- Type Parameters:
- T- The class type to get the meta-data on.
- Parameters:
- c- The class to get the meta-data on.
- Returns:
- The BeanMetafor the specified class, ornull if the class is not a bean per the settings on this context.
 
- 
getClassMetaReturns aClassMetawrapper around aClassobject.- Type Parameters:
- T- The class type being wrapped.
- Parameters:
- c- The class being wrapped.
- Returns:
- The class meta object containing information about the class.
 
- 
getClassMetaUsed to resolveClassMetas of typeCollection andMap that haveClassMeta values that themselves could be collections or maps.Collection meta objects are assumed to be followed by zero or one meta objects indicating the element type.Map meta objects are assumed to be followed by zero or two meta objects indicating the key and value types.The array can be arbitrarily long to indicate arbitrarily complex data structures. Examples:- getClassMeta(String.- A normal type.- class );
- getClassMeta(List.- A list containing objects.- class );
- getClassMeta(List.- A list containing strings.- class , String.- class );
- getClassMeta(LinkedList.- A linked-list containing strings.- class , String.- class );
- getClassMeta(LinkedList.- A linked-list containing linked-lists of strings.- class , LinkedList.- class , String.- class );
- getClassMeta(Map.- A map containing object keys/values.- class );
- getClassMeta(Map.- A map containing string keys/values.- class , String.- class , String.- class );
- getClassMeta(Map.- A map containing string keys and values of lists containing beans.- class , String.- class , List.- class , MyBean.- class );
 - Type Parameters:
- T- The class to resolve.
- Parameters:
- type- The class to resolve.
 Can be any of the following:- ClassMeta,- Class,- ParameterizedType,- GenericArrayType
- args- The type arguments of the class if it's a collection or map.
 Can be any of the following:- ClassMeta,- Class,- ParameterizedType,- GenericArrayType
 Ignored if the main type is not a map or collection.
- Returns:
- The class meta.
 
- 
getArgsClassMetaGiven an array ofTypeobjects, returns aClassMetarepresenting those arguments.Constructs a new meta on each call. - Parameters:
- classes- The array of classes to get class metas for.
- Returns:
- The args ClassMetaobject corresponding to the classes. Nevernull .
 
- 
getClassMetaForObjectShortcut for callinggetClassMeta(o.getClass()).- Type Parameters:
- T- The class of the object being passed in.
- Parameters:
- o- The class to find the class type for.
- Returns:
- The ClassMeta object, or null ifoisnull .
 
- 
getClassMetaForObjectShortcut for callinggetClassMeta(o.getClass())but returns a default value if object isnull .- Parameters:
- o- The class to find the class type for.
- def- The default- ClassMetaif the object is null.
- Returns:
- The ClassMeta object, or the default value if oisnull .
 
- 
getLocaleLocale.The locale is determined in the following order: - locale parameter passed in through constructor.
- BeanContext.Builder.locale(Locale)setting on bean context.
- Locale returned by Locale.getDefault().
 - Returns:
- The session locale.
- See Also:
 
- 
getMediaTypeMedia type.For example, "application/json" .- Returns:
- The media type for this session, or null if not specified.
- See Also:
 
- 
getBeanTypePropertyNameReturns the type property name as defined byBeanContext.Builder.typePropertyName(String).- Parameters:
- cm- The class meta of the type we're trying to resolve the type name for. Can be- null .
- Returns:
- The type property name.  Never null .
 
- 
getNamePropertyNameReturns the name property name.Currently this always returns "_name" .- Returns:
- The name property name.  Never null .
 
- 
getBeanRegistryReturns the bean registry defined in this bean context defined byBeanContext.Builder.beanDictionary(Class...).- Returns:
- The bean registry defined in this bean context.  Never null .
 
- 
objectReturns a reusableClassMetarepresentation for the classObject .This ClassMeta is often used to represent "any object type" when an object type is not known.This method is identical to calling getClassMeta(Object.but uses a cached copy to avoid a hashmap lookup.class )- Returns:
- The ClassMetaobject associated with theObject class.
 
- 
stringReturns a reusableClassMetarepresentation for the classString .This ClassMeta is often used to represent key types in maps.This method is identical to calling getClassMeta(String.but uses a cached copy to avoid a hashmap lookup.class )- Returns:
- The ClassMetaobject associated with theString class.
 
- 
_classReturns a reusableClassMetarepresentation for the classClass .This ClassMeta is often used to represent key types in maps.This method is identical to calling getClassMeta(Class.but uses a cached copy to avoid a hashmap lookup.class )- Returns:
- The ClassMetaobject associated with theString class.
 
- 
newGenericMapCreates either anJsonMaporLinkedHashMapdepending on whether the key type is String or something else.- Parameters:
- mapMeta- The metadata of the map to create.
- Returns:
- A new map.
 
- 
addWarningLogs a warning message.- Overrides:
- addWarningin class- ContextSession
- Parameters:
- msg- The warning message.
- args- Optional- MessageFormat-style arguments.
 
- 
getBeanClassVisibilityMinimum bean class visibility.- Returns:
- Classes are not considered beans unless they meet the minimum visibility requirements.
- See Also:
 
- 
getBeanConstructorVisibilityMinimum bean constructor visibility.- Returns:
- Only look for constructors with this specified minimum visibility.
- See Also:
 
- 
getBeanDictionaryBean dictionary.- Returns:
- The list of classes that make up the bean dictionary in this bean context.
- See Also:
 
- 
getBeanFieldVisibilityMinimum bean field visibility.- Returns:
- Only look for bean fields with this specified minimum visibility.
- See Also:
 
- 
isBeanMapPutReturnsOldValueBeanMap.put() returns old property value.- Returns:
- true if the- BeanMap.put()method will return old property values.
 Otherwise, it returns- null .
- See Also:
 
- 
getBeanMethodVisibilityMinimum bean method visibility.- Returns:
- Only look for bean methods with this specified minimum visibility.
- See Also:
 
- 
isBeansRequireDefaultConstructorBeans require no-arg constructors.- Returns:
- true if 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.
- See Also:
 
- 
isBeansRequireSerializableBeans require Serializable interface.- Returns:
- true if a Java class must implement the- Serializableinterface to be considered a bean.
 Otherwise, the bean will be serialized as a string using the- Object.toString()method.
- See Also:
 
- 
isBeansRequireSettersForGettersBeans require setters for getters.- Returns:
- true if only getters that have equivalent setters will be considered as properties on a bean.
 Otherwise, they are ignored.
- See Also:
 
- 
isBeansRequireSomePropertiesBeans require at least one property.- Returns:
- true if a Java class doesn't need to contain at least 1 property to be considered a bean.
 Otherwise, the bean is serialized as a string using the- Object.toString()method.
- See Also:
 
- 
getBeanTypePropertyNameBean type property name.- Returns:
- 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.
- See Also:
 
- 
isFindFluentSettersFind fluent setters.Description:- Returns:
- true if fluent setters are detected on beans.
- See Also:
 
- 
isIgnoreInvocationExceptionsOnGettersIgnore invocation errors on getters.- Returns:
- true if errors thrown when calling bean getter methods are silently ignored.
- See Also:
 
- 
isIgnoreInvocationExceptionsOnSettersIgnore invocation errors on setters.- Returns:
- true if errors thrown when calling bean setter methods are silently ignored.
- See Also:
 
- 
isIgnoreMissingSettersSilently ignore missing setters.- Returns:
- true if trying to set a value on a bean property without a setter should throw a- BeanRuntimeException.
- See Also:
 
- 
isIgnoreUnknownBeanPropertiesIgnore unknown properties.- Returns:
- true if trying to set a value on a non-existent bean property is silently ignored.
 Otherwise, a- RuntimeExceptionis thrown.
- See Also:
 
- 
isIgnoreUnknownNullBeanPropertiesIgnore unknown properties with null values.- Returns:
- true if trying to set a- null value on a non-existent bean property should not throw a- BeanRuntimeException.
- See Also:
 
- 
getNotBeanClassesBean class exclusions.- Returns:
- The list of classes that are explicitly not beans.
- See Also:
 
- 
getNotBeanPackagesNamesBean package exclusions.- Returns:
- The list of fully-qualified package names to exclude from being classified as beans.
- See Also:
 
- 
getNotBeanPackagesPrefixesBean package exclusions.- Returns:
- The list of package name prefixes to exclude from being classified as beans.
- See Also:
 
- 
getPropertyNamerBean property namer.- Returns:
- The interface used to calculate bean property names.
- See Also:
 
- 
isSortPropertiesSort bean properties.- Returns:
- true if all bean properties will be serialized and access in alphabetical order.
- See Also:
 
- 
getSwapsJava object swaps.- Returns:
- The list POJO swaps defined.
- See Also:
 
- 
getTimeZoneTime zone.The timezone is determined in the following order: - timeZone parameter passed in through constructor.
- BeanContext.Builder.timeZone(TimeZone)setting on bean context.
 - Returns:
- The session timezone, or null if timezone not specified.
- See Also:
 
- 
getTimeZoneIdTime zone.The timezone is determined in the following order: - timeZone parameter passed in through constructor.
- BeanContext.Builder.timeZone(TimeZone)setting on bean context.
 - Returns:
- The session timezone, or the system timezone if not specified.  Never null .
- See Also:
 
- 
isUseEnumNamesUse enum names.- Returns:
- true if enums are always serialized by name, not using- Object.toString().
- See Also:
 
- 
isUseInterfaceProxiesUse interface proxies.- Returns:
- true if interfaces will be instantiated as proxy classes through the use of an- InvocationHandlerif there is no other way of instantiating them.
- See Also:
 
- 
isUseJavaBeanIntrospectorUse Java Introspector.- Returns:
- true if the built-in Java bean introspector should be used for bean introspection.
- See Also:
 
 
-