Class AbstractConverter<SOURCE,TARGET>

java.lang.Object
de.hybris.platform.converters.impl.AbstractConverter<SOURCE,TARGET>
All Implemented Interfaces:
Populator<SOURCE,TARGET>, Converter<SOURCE,TARGET>, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean, org.springframework.core.convert.converter.Converter<SOURCE,TARGET>
Direct Known Subclasses:
AbstractErrorConverter, AbstractPopulatingConverter, CartVoucherValidationErrorConverter, CartVoucherValidationErrorConverter, PosConverter, ProductConverter

public abstract class AbstractConverter<SOURCE,TARGET> extends Object implements Converter<SOURCE,TARGET>, Populator<SOURCE,TARGET>, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.BeanNameAware
Abstract implementation of the Converter interface that also supports the Populator interface. Implementations of this base type can either be used as a converter or as a populator. When used as a converter the createTarget() method is called to create the target instance and then the populate(Object, Object) method is called to populate the target with values from the source instance. The createTarget() method can be implemented via a spring lookup-method rather than being overridden in code.
  • Constructor Details

    • AbstractConverter

      public AbstractConverter()
  • Method Details

    • convert

      public TARGET convert(SOURCE source) throws ConversionException
      Description copied from interface: Converter
      Converts the source object, creating a new instance of the destination type
      Specified by:
      convert in interface Converter<SOURCE,TARGET>
      Specified by:
      convert in interface org.springframework.core.convert.converter.Converter<SOURCE,TARGET>
      Parameters:
      source - the source object
      Returns:
      the converted object
      Throws:
      ConversionException - if an error occurs
    • convert

      public TARGET convert(SOURCE source, TARGET prototype) throws ConversionException
      Description copied from interface: Converter
      Convert the source object by filling the prototype
      Specified by:
      convert in interface Converter<SOURCE,TARGET>
      Parameters:
      source - the source object
      prototype - the prototype to fill
      Returns:
      the converted object, identical to the prototype
      Throws:
      ConversionException - if an error occurs
    • populate

      public abstract void populate(SOURCE source, TARGET target)
      Override this method to populate the target from the source
      Specified by:
      populate in interface Populator<SOURCE,TARGET>
      Parameters:
      source - the source instance
      target - the target instance to fill
      See Also:
    • setTargetClass

      public void setTargetClass(Class<TARGET> targetClass)
      Allows to specify the target object class directly. Please use that instead of the deprecated <lookup-method name="createTarget" ref="bean"> approach, as it's way faster.
    • createFromClass

      protected TARGET createFromClass()
    • createTarget

      @Deprecated(since="ages", forRemoval=true) protected TARGET createTarget()
      Deprecated, for removal: This API element is subject to removal in a future version.
      please inject the target class directly, since it's way faster than the Spring <lookup-method> approach!
    • setBeanName

      public void setBeanName(String name)
      Specified by:
      setBeanName in interface org.springframework.beans.factory.BeanNameAware
    • getMyBeanName

      public String getMyBeanName()
    • afterPropertiesSet

      public void afterPropertiesSet() throws Exception
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
      Throws:
      Exception