Class DefaultMapper

  • All Implemented Interfaces:
    Mapper

    public class DefaultMapper
    extends java.lang.Object
    implements Mapper
    Default mapper implementation with 'vanilla' functionality.

    To build up the functionality required, wrap this mapper with other mapper implementations.

    • Field Detail

      • XSTREAM_PACKAGE_ROOT

        private static java.lang.String XSTREAM_PACKAGE_ROOT
    • Constructor Detail

      • DefaultMapper

        public DefaultMapper​(ClassLoaderReference classLoaderReference)
        Construct a DefaultMapper.
        Parameters:
        classLoaderReference - the reference to the classloader used by the XStream instance.
        Since:
        1.4.5
      • DefaultMapper

        public DefaultMapper​(java.lang.ClassLoader classLoader)
        Deprecated.
        Construct a DefaultMapper.
        Parameters:
        classLoader - the ClassLoader used by the XStream instance.
    • 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
      • realClass

        public java.lang.Class realClass​(java.lang.String elementName)
        Description copied from interface: Mapper
        How a serialized class representation should be mapped back to a real class.
        Specified by:
        realClass in interface Mapper
      • defaultImplementationOf

        public java.lang.Class defaultImplementationOf​(java.lang.Class type)
        Specified by:
        defaultImplementationOf in interface Mapper
      • aliasForAttribute

        public java.lang.String aliasForAttribute​(java.lang.String attribute)
        Description copied from interface: Mapper
        Get the alias for an attribute's name.
        Specified by:
        aliasForAttribute in interface Mapper
        Parameters:
        attribute - the attribute
        Returns:
        the alias
      • attributeForAlias

        public java.lang.String attributeForAlias​(java.lang.String alias)
        Description copied from interface: Mapper
        Get the attribute's name for an alias.
        Specified by:
        attributeForAlias in interface Mapper
        Parameters:
        alias - the alias
        Returns:
        the attribute's name
      • aliasForSystemAttribute

        public java.lang.String aliasForSystemAttribute​(java.lang.String attribute)
        Description copied from interface: Mapper
        Get the alias for a system attribute's name.
        Specified by:
        aliasForSystemAttribute in interface Mapper
        Parameters:
        attribute - the system attribute
        Returns:
        the alias
      • 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
      • isReferenceable

        public boolean isReferenceable​(java.lang.Class type)
        Description copied from interface: Mapper
        Whether this type is referenceable in a stream.
        Specified by:
        isReferenceable in interface Mapper
      • getFieldNameForItemTypeAndName

        public java.lang.String getFieldNameForItemTypeAndName​(java.lang.Class definedIn,
                                                               java.lang.Class itemType,
                                                               java.lang.String itemFieldName)
        Description copied from interface: Mapper
        Get the name of the field that acts as the default collection for an object, or return null if there is none.
        Specified by:
        getFieldNameForItemTypeAndName in interface Mapper
        Parameters:
        definedIn - owning type
        itemType - item type
        itemFieldName - optional item element name
      • getItemTypeForItemFieldName

        public java.lang.Class getItemTypeForItemFieldName​(java.lang.Class definedIn,
                                                           java.lang.String itemFieldName)
        Specified by:
        getItemTypeForItemFieldName in interface Mapper
      • shouldSerializeMember

        public boolean shouldSerializeMember​(java.lang.Class definedIn,
                                             java.lang.String fieldName)
        Description copied from interface: Mapper
        Determine whether a specific member should be serialized.
        Specified by:
        shouldSerializeMember in interface Mapper
      • isIgnoredElement

        public boolean isIgnoredElement​(java.lang.String name)
        Description copied from interface: Mapper
        Whether this name can be ignored.
        Specified by:
        isIgnoredElement in interface Mapper
      • lookupName

        public java.lang.String lookupName​(java.lang.Class type)
      • lookupType

        public java.lang.Class lookupType​(java.lang.String elementName)
      • serializedMember

        public java.lang.String serializedMember​(java.lang.Class type,
                                                 java.lang.String memberName)
        Description copied from interface: Mapper
        How a class member should be represented in its serialized form.
        Specified by:
        serializedMember in interface Mapper
      • realMember

        public java.lang.String realMember​(java.lang.Class type,
                                           java.lang.String serialized)
        Description copied from interface: Mapper
        How a serialized member representation should be mapped back to a real member.
        Specified by:
        realMember in interface Mapper
      • 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
        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.
      • getLocalConverter

        public Converter getLocalConverter​(java.lang.Class definedIn,
                                           java.lang.String fieldName)
        Specified by:
        getLocalConverter in interface Mapper
      • aliasForAttribute

        public java.lang.String aliasForAttribute​(java.lang.Class definedIn,
                                                  java.lang.String fieldName)
        Description copied from interface: Mapper
        Returns an alias for a single field defined in an specific type.
        Specified by:
        aliasForAttribute in interface Mapper
        Parameters:
        definedIn - the type where the field was defined
        fieldName - the field name
        Returns:
        the alias for this field or its own name if no alias was defined
      • attributeForAlias

        public java.lang.String attributeForAlias​(java.lang.Class definedIn,
                                                  java.lang.String alias)
        Deprecated.
        Description copied from interface: Mapper
        Returns the field name for an aliased attribute.
        Specified by:
        attributeForAlias in interface Mapper
        Parameters:
        definedIn - the type where the field was defined
        alias - the alias
        Returns:
        the original attribute name
      • 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
        Parameters:
        definedIn - the field's parent
        attribute - the attribute name
        type - the type the converter should create