Package com.thoughtworks.xstream.mapper
Class EnumMapper
- java.lang.Object
-
- com.thoughtworks.xstream.mapper.MapperWrapper
-
- com.thoughtworks.xstream.mapper.EnumMapper
-
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.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.thoughtworks.xstream.mapper.Mapper
Mapper.ImplicitCollectionMapping, Mapper.Null
-
-
Field Summary
Fields Modifier and Type Field Description private AttributeMapper
attributeMapper
private java.util.Map<java.lang.Class,SingleValueConverter>
enumConverterMap
-
Constructor Summary
Constructors Constructor Description EnumMapper(Mapper wrapped)
EnumMapper(Mapper wrapped, ConverterLookup lookup)
Deprecated.As of 1.3.1, useEnumMapper(Mapper)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
flushCache()
SingleValueConverter
getConverterFromAttribute(java.lang.Class definedIn, java.lang.String attribute, java.lang.Class type)
Returns which converter to use for an specific attribute in a type.SingleValueConverter
getConverterFromItemType(java.lang.String fieldName, java.lang.Class type, java.lang.Class definedIn)
Returns a single value converter to be used in a specific field.private SingleValueConverter
getLocalConverter(java.lang.String fieldName, java.lang.Class type, java.lang.Class definedIn)
boolean
isImmutableValueType(java.lang.Class type)
Whether this type is a simple immutable value (int, boolean, String, URL, etc).boolean
isReferenceable(java.lang.Class type)
Whether this type is referenceable in a stream.private java.lang.Object
readResolve()
java.lang.String
serializedClass(java.lang.Class type)
How a class name should be represented in its serialized form.-
Methods inherited from class com.thoughtworks.xstream.mapper.MapperWrapper
aliasForAttribute, aliasForAttribute, aliasForSystemAttribute, attributeForAlias, attributeForAlias, defaultImplementationOf, getConverterFromAttribute, getConverterFromAttribute, getConverterFromItemType, getConverterFromItemType, getFieldNameForItemTypeAndName, getImplicitCollectionDefForFieldName, getItemTypeForItemFieldName, getLocalConverter, isIgnoredElement, lookupMapperOfType, realClass, realMember, serializedMember, shouldSerializeMember
-
-
-
-
Field Detail
-
attributeMapper
private transient AttributeMapper attributeMapper
-
enumConverterMap
private transient java.util.Map<java.lang.Class,SingleValueConverter> enumConverterMap
-
-
Constructor Detail
-
EnumMapper
@Deprecated public EnumMapper(Mapper wrapped, ConverterLookup lookup)
Deprecated.As of 1.3.1, useEnumMapper(Mapper)
-
EnumMapper
public EnumMapper(Mapper wrapped)
-
-
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 interfaceMapper
- Overrides:
serializedClass
in classMapperWrapper
-
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 interfaceMapper
- Overrides:
isImmutableValueType
in classMapperWrapper
-
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 interfaceMapper
- Overrides:
isReferenceable
in classMapperWrapper
-
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 interfaceMapper
- Overrides:
getConverterFromItemType
in classMapperWrapper
- Parameters:
fieldName
- the field nametype
- the field typedefinedIn
- 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 interfaceMapper
- Overrides:
getConverterFromAttribute
in classMapperWrapper
- Parameters:
definedIn
- the field's parentattribute
- the attribute nametype
- 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 interfaceCaching
-
readResolve
private java.lang.Object readResolve()
-
-