Class 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, PosConverter, ProductConverter

    public abstract class AbstractConverter<SOURCE,​TARGET>
    extends java.lang.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 Detail

      • AbstractConverter

        public AbstractConverter()
    • Method Detail

      • 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(Class)
      • setTargetClass

        public void setTargetClass​(java.lang.Class<TARGET> targetClass)
        Allows to specify the target object class directly. Please use that instead of the deprecated approach, as it's way faster.
      • createFromClass

        protected TARGET createFromClass()
      • createTarget

        @Deprecated
        protected TARGET createTarget()
        Deprecated.
        please inject the target class directly, since it's way faster than the Spring approach!
      • setBeanName

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

        public java.lang.String getMyBeanName()
      • afterPropertiesSet

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