Class Wrapper<T>

  • All Implemented Interfaces:
    AnnotatedElement
    Direct Known Subclasses:
    BeanCreator, BeanViewConverter, ClassMetadataConverter, MissingClassConverter, RuntimeTypeConverter, SerializationSupportConverter

    public abstract class Wrapper<T>
    extends Object
    implements AnnotatedElement
    Wrapper class must be extended by decorated converters that wrap other converters. This allows to access merged class information of wrapped converter and the converter itself. So instead of doing myObject.getClass().isAnnotationPresent(..) you will do myObject.isAnnotationPresent(..), where myObject is an instance of Wrapper. For example to check if a converter (or any another encapsulated converter and so on) has annotation @HandleNull you will do it that way:

     Wrapper.toAnnotatedElement(converter).isAnnotationPresent(HandleNull.class);
     

    In the future there may be other methods to access other kind of class information.

    Author:
    Eugen Cepoi
    • Field Detail

      • wrapped

        protected volatile T wrapped
    • Constructor Detail

      • Wrapper

        protected Wrapper()
      • Wrapper

        protected Wrapper​(T wrappedObject)
    • Method Detail

      • decorate

        protected void decorate​(T object)
      • unwrap

        public T unwrap()
      • toAnnotatedElement

        public static AnnotatedElement toAnnotatedElement​(Object object)
        This method acts as an adapter to AnnotatedElement, use it when you need to work on a converter annotations. In fact "object" argument will usually be of type converter. If this class is a wrapper than it will cast it to annotatedElement (as Wrapper implements AnnotatedElement). Otherwise we will return the class of this object.
        Parameters:
        object - may be an instance of converter for example
        Returns:
        an annotatedElement that allows us to get annotations from this object and it's wrapped classes if it is a Wrapper.
      • isWrapped

        public static boolean isWrapped​(Object object)
      • isOfType

        public static boolean isOfType​(Object object,
                                       Class<?> clazz)
        Returns:
        true if this object or its wrapped object (if the object extends Wrapper) is of type clazz.