Class PersistentBeanConverter
java.lang.Object
de.ppi.deepsampler.persistence.bean.PersistentBeanConverter
public class PersistentBeanConverter
extends java.lang.Object
DeepSampler saves Beans by converting them in an abstract model that enables DeepSampler to omit type information in persistent files.
This approach makes persistent beans less vulnerable to refactorings. E.g. it is not necessary to rename classes in persistent Sample-files
if classes are renamed during refactorings.
The concrete serialization / Deserialization is done by an underlying persistence api. PersistentBeanConverter is only responsible to to create an intermediate data structures for cases where the persistence api is not capable to serialize / deserialize the original data on its own.
-
Constructor Summary
Constructors Constructor Description PersistentBeanConverter() -
Method Summary
Modifier and Type Method Description voidaddExtension(BeanConverterExtension extension)<T> Tconvert(java.lang.Object originalBean, java.lang.reflect.Type type)Converts an original bean to the abstract model (most likelyPersistentBean) that is used to save the original bean to e.g.<T> Trevert(java.lang.Object persistentBean, java.lang.Class<T> originalBeanClass, java.lang.reflect.ParameterizedType parameterizedType)Reverts an abstract model from the persistence to the original bean.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
PersistentBeanConverter
public PersistentBeanConverter()
-
-
Method Details
-
addExtension
-
revert
public <T> T revert(java.lang.Object persistentBean, java.lang.Class<T> originalBeanClass, java.lang.reflect.ParameterizedType parameterizedType)Reverts an abstract model from the persistence to the original bean.If more than one applicable
BeanConverterExtensionis found, the last registered one will be used.- Type Parameters:
T- the original bean.- Parameters:
persistentBean- an object that has been deserialized by a persistence api (e.g. some JSON-API). This object might already be the original bean, if the persistence api was able to deserialize it. Otherwise, it is the abstract model represented byPersistentBeanparameterizedType- The Type of the original bean- Returns:
- the original deserialized bean.
-
convert
public <T> T convert(java.lang.Object originalBean, java.lang.reflect.Type type)Converts an original bean to the abstract model (most likelyPersistentBean) that is used to save the original bean to e.g. JSON.If more than one applicable
BeanConverterExtensionis found, the last registered one will be used.- Type Parameters:
T- The type of the persistent bean.- Parameters:
originalBean- The original Bean that is supposed to be persisted.- Returns:
- The object that will be sent to the underlying persistence api. This might be a
PersistentBeanor the original bean if the persistence api is expected to be able to serialize the original bean directly.
-