Class EnumMapper

  • All Implemented Interfaces:
    Caching, Mapper

    public class EnumMapper
    extends MapperWrapper
    implements Caching
    Mapper that handles the special case of polymorphic enums in Java 1.5. This renames MyEnum$1 to MyEnum making it less bloaty in the XML and avoiding the need for an alias per enum value to be specified. Additionally every enum is treated automatically as immutable and non-refrenceable type that can be written as attribute.
    • Method Detail

      • serializedClass

        public java.lang.String serializedClass​(java.lang.Class type)
        Description copied from interface: Mapper
        How a class name should be represented in its serialized form.
        Specified by:
        serializedClass in interface Mapper
        Overrides:
        serializedClass in class MapperWrapper
      • isImmutableValueType

        public boolean isImmutableValueType​(java.lang.Class type)
        Description copied from interface: Mapper
        Whether this type is a simple immutable value (int, boolean, String, URL, etc). Immutable types will be repeatedly written in the serialized stream, instead of using object references.
        Specified by:
        isImmutableValueType in interface Mapper
        Overrides:
        isImmutableValueType in class MapperWrapper
      • getConverterFromItemType

        public SingleValueConverter getConverterFromItemType​(java.lang.String fieldName,
                                                             java.lang.Class type,
                                                             java.lang.Class definedIn)
        Description copied from interface: Mapper
        Returns a single value converter to be used in a specific field.
        Specified by:
        getConverterFromItemType in interface Mapper
        Overrides:
        getConverterFromItemType in class MapperWrapper
        Parameters:
        fieldName - the field name
        type - the field type
        definedIn - the type which defines this field
        Returns:
        a SingleValueConverter or null if there no such converter should be used for this field.
      • getConverterFromAttribute

        public SingleValueConverter getConverterFromAttribute​(java.lang.Class definedIn,
                                                              java.lang.String attribute,
                                                              java.lang.Class type)
        Description copied from interface: Mapper
        Returns which converter to use for an specific attribute in a type.
        Specified by:
        getConverterFromAttribute in interface Mapper
        Overrides:
        getConverterFromAttribute in class MapperWrapper
        Parameters:
        definedIn - the field's parent
        attribute - the attribute name
        type - the type the converter should create
      • getLocalConverter

        private SingleValueConverter getLocalConverter​(java.lang.String fieldName,
                                                       java.lang.Class type,
                                                       java.lang.Class definedIn)
      • flushCache

        public void flushCache()
        Specified by:
        flushCache in interface Caching
      • readResolve

        private java.lang.Object readResolve()