Class MapPrimitiveKeyExtension
- All Implemented Interfaces:
BeanConverterExtension
public class MapPrimitiveKeyExtension extends StandardBeanConverterExtension
BeanConverterExtension is able to convert Maps into a persistable model that can be sent to
the underlying persistence api and vice versa.
This extension is limited to Maps that have a primitive key (i.e. wrapper types of primitives, since Maps can't
hold primitives directly)
The values of the Map can either be primitives (i.e. wrappers) or complex objects. In the first case, the values will be
sent directly to the persistence api. In the latter case, the values will be converted to PersistentBeans
during the serialization process.
The original Map-types are preserved in most cases. But in some rare cases this is not possible because the original Maps
are not visible, or don't provide a adequate constructor. This is i.e. the case for Maps that have been created using
Collections.unmodifiableMap(Map). In cases like this, the original Map is replaced by a common HashMap.
This is a default extension that is always active.
-
Constructor Summary
Constructors Constructor Description MapPrimitiveKeyExtension() -
Method Summary
Modifier and Type Method Description java.lang.Objectconvert(java.lang.Object originalBean, java.lang.reflect.ParameterizedType beanType, PersistentBeanConverter persistentBeanConverter)Conversion logic for the type you defined to process and not to skip.booleanisProcessable(java.lang.Class<?> beanClass, java.lang.reflect.ParameterizedType beanType)Checks it this extension is responsible for objects of the type beanType.<T> Trevert(java.lang.Object persistentBean, java.lang.Class<T> targetClass, java.lang.reflect.ParameterizedType type, PersistentBeanConverter persistentBeanConverter)Conversion logic for the generic data-structure to the processed bean type.Methods inherited from class de.ppi.deepsampler.persistence.bean.ext.StandardBeanConverterExtension
skipMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
MapPrimitiveKeyExtension
public MapPrimitiveKeyExtension()
-
-
Method Details
-
isProcessable
public boolean isProcessable(java.lang.Class<?> beanClass, java.lang.reflect.ParameterizedType beanType)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.beanType- 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
-
convert
public java.lang.Object convert(java.lang.Object originalBean, java.lang.reflect.ParameterizedType beanType, 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.beanType- 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> targetClass, java.lang.reflect.ParameterizedType type, 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 beantargetClass- theClassof the type that will be created from the persistentBean.type- 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
-