Class CollectionExtension
- All Implemented Interfaces:
BeanConverterExtension
public class CollectionExtension extends StandardBeanConverterExtension
BeanConverterExtension that is able to convert Collections from the original objects to the generic persistent
model PersistentBean and vice versa.
Only Collectionss with elements of non-primitive types (i.e. their wrapper) are processed by this extension, since
the underlying persistence api is expected to be fully capable of dealing with simple Collections that contain only primitive values.
The original type of the Collection will we preserved in most cases. If this is not possible, the original Collection is replaced by
an ArrayList or a HashSet depending on the original Collection. E.G. this happens for Lists that have been
created by Collections.unmodifiableCollection(Collection) or Arrays.asList(Object[]).
This is a default BeanConverterExtension that is always enabled.
-
Constructor Summary
Constructors Constructor Description CollectionExtension() -
Method Summary
Modifier and Type Method Description java.lang.Objectconvert(java.lang.Object originalBean, java.lang.reflect.ParameterizedType parameterizedType, PersistentBeanConverter persistentBeanConverter)Conversion logic for the type you defined to process and not to skip.booleanisProcessable(java.lang.Class<?> beanClass, java.lang.reflect.ParameterizedType parameterizedType)Checks it this extension is responsible for objects of the type beanType.<T> Trevert(java.lang.Object persistentBean, java.lang.Class<T> targetBeanClass, java.lang.reflect.ParameterizedType targetBeanType, PersistentBeanConverter persistentBeanConverter)Conversion logic for the generic data-structure to the processed bean type.booleanskip(java.lang.Class<?> beanClass, java.lang.reflect.ParameterizedType beanType)We skip the conversion of all Collections, which have primitive (or their wrapper) generic types.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
CollectionExtension
public CollectionExtension()
-
-
Method Details
-
isProcessable
public boolean isProcessable(java.lang.Class<?> beanClass, java.lang.reflect.ParameterizedType parameterizedType)Description copied from interface:BeanConverterExtensionChecks it this extension is responsible for objects of the type beanType.- Parameters:
beanClass- theClassof the type that will be processed by this extension.parameterizedType- theParameterizedTypeof the type that will be processed by this extension. This parameter can only be supplied if the type is actually a generic type. If this is not the case, beanType is null.- Returns:
- true if the
Typeshould be processed within this extension, false otherwise
-
skip
public boolean skip(java.lang.Class<?> beanClass, java.lang.reflect.ParameterizedType beanType)We skip the conversion of all Collections, which have primitive (or their wrapper) generic types. Primitive Collections will then be handled by the concrete persistence api (i.e. Jackson for JSON serialisation).- Specified by:
skipin interfaceBeanConverterExtension- Overrides:
skipin classStandardBeanConverterExtension- Parameters:
beanType- theTypeof the bean (Collection is expected here) that is handled by thisBeanConverterExtensionbeanClass- theClassof the type that will be skipped by this extension.- Returns:
- true if beanType is a primitive
Collection
-
convert
public java.lang.Object convert(java.lang.Object originalBean, java.lang.reflect.ParameterizedType parameterizedType, PersistentBeanConverter persistentBeanConverter)Description copied from interface:BeanConverterExtensionConversion logic for the type you defined to process and not to skip. Converts an original bean to thePersistentBeanwhich will be sent to the persistence api.It is also possible to convert bean to any other data structure if the underlying persistence api is fully capable of handling the data structure on its own.
- Specified by:
convertin interfaceBeanConverterExtension- Overrides:
convertin classStandardBeanConverterExtension- Parameters:
originalBean- the original bean that is supposed to be converted to a serializable data structure, most likely aPersistentBean.parameterizedType- theParameterizedTypethat will be used for the conversion. This parameter can only be supplied if the type is actually a generic type. If this is not the case, beanType is null.persistentBeanConverter- the currentPersistentBeanConverterthat may be used to convert sub objects of bean.- Returns:
- the generic data-structure for the bean
-
revert
public <T> T revert(java.lang.Object persistentBean, java.lang.Class<T> targetBeanClass, java.lang.reflect.ParameterizedType targetBeanType, PersistentBeanConverter persistentBeanConverter)Description copied from interface:BeanConverterExtensionConversion logic for the generic data-structure to the processed bean type. Reverts to the original Bean by converting thePersistentBean, which was deserialized by the underlying persistence api, to the original object.It is also possible to deserialize other types then
PersistentBeanif the underlying persistence api is fully capable of deserializing this type.revert() is not called, if the persisted value is null. In that case, null will be returned as the deserialized value without calling an extension. If null needs to be converted, the value must be encapsulated in a
DefaultPersistentBean.- Specified by:
revertin interfaceBeanConverterExtension- Overrides:
revertin classStandardBeanConverterExtension- Type Parameters:
T- type of the original bean- Parameters:
persistentBean- the generic beantargetBeanClass- theClassof the type that will be created from the persistentBean.targetBeanType- theParameterizedTypefor the type that will be created from persistentBean, This parameter can only be supplied if the type is actually a generic type. If this is not the case, targetType is null.persistentBeanConverter- the currentPersistentBeanConverterthat may be used to revert sub objects of persistentBean.- Returns:
- original bean
-