Class OptionalExtension

java.lang.Object
de.ppi.deepsampler.persistence.bean.ext.StandardBeanConverterExtension
de.ppi.deepsampler.persistence.bean.ext.OptionalExtension
All Implemented Interfaces:
BeanConverterExtension

public class OptionalExtension
extends StandardBeanConverterExtension
A BeanConverterExtension that is able to record and load Optional values. The Optional is encapsulated in a DefaultPersistentBean, because the PersistentBeanConverter does not pass null values to BeanConverterExtensions during deserialization. Instead, null values are returned as the deserialized value without further conversions. This is a design decision that is based on the assumption that null values usually don't need to be converted in most cases.

OptionalExtension is capable of de-/serializing recursively, so that Optionals value will also be converted, if necessary.

  • Field Summary

    Fields
    Modifier and Type Field Description
    static java.lang.String OPTIONAL_PROPERTY  
  • Constructor Summary

    Constructors
    Constructor Description
    OptionalExtension()  
  • Method Summary

    Modifier and Type Method Description
    java.lang.Object convert​(java.lang.Object originalBean, java.lang.reflect.ParameterizedType beanType, PersistentBeanConverter persistentBeanConverter)
    Conversion logic for the type you defined to process and not to skip.
    boolean isProcessable​(java.lang.Class<?> beanClass, java.lang.reflect.ParameterizedType beanType)
    Checks it this extension is responsible for objects of the type beanType.
    <T> T revert​(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

    skip

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • OPTIONAL_PROPERTY

      public static final java.lang.String OPTIONAL_PROPERTY
      See Also:
      Constant Field Values
  • Constructor Details

    • OptionalExtension

      public OptionalExtension()
  • Method Details

    • isProcessable

      public boolean isProcessable​(java.lang.Class<?> beanClass, java.lang.reflect.ParameterizedType beanType)
      Description copied from interface: BeanConverterExtension
      Checks it this extension is responsible for objects of the type beanType.
      Parameters:
      beanClass - the Class of the type that will be processed by this extension.
      beanType - the ParameterizedType of 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 Type should 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: BeanConverterExtension
      Conversion logic for the type you defined to process and not to skip. Converts an original bean to the PersistentBean which 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:
      convert in interface BeanConverterExtension
      Overrides:
      convert in class StandardBeanConverterExtension
      Parameters:
      originalBean - the original bean that is supposed to be converted to a serializable data structure, most likely a PersistentBean.
      beanType - the ParameterizedType that 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 current PersistentBeanConverter that 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: BeanConverterExtension
      Conversion logic for the generic data-structure to the processed bean type. Reverts to the original Bean by converting the PersistentBean, which was deserialized by the underlying persistence api, to the original object.

      It is also possible to deserialize other types then PersistentBean if 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:
      revert in interface BeanConverterExtension
      Overrides:
      revert in class StandardBeanConverterExtension
      Type Parameters:
      T - type of the original bean
      Parameters:
      persistentBean - the generic bean
      targetClass - the Class of the type that will be created from the persistentBean.
      type - the ParameterizedType for 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 current PersistentBeanConverter that may be used to revert sub objects of persistentBean.
      Returns:
      original bean