Class NamedMapConverter
- java.lang.Object
-
- com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter
-
- com.thoughtworks.xstream.converters.collections.MapConverter
-
- com.thoughtworks.xstream.converters.extended.NamedMapConverter
-
- All Implemented Interfaces:
Converter
,ConverterMatcher
public class NamedMapConverter extends MapConverter
A map converter that uses predefined names for its elements.To be used as local converter. Note, suppress the usage of the implicit type argument, if registered with annotation. Depending on the constructor arguments it is possible to support various formats:
- new NamedMapConverter(xstream.getMapper(), "entry", "key", String.class, "value",
Integer.class);
<map> <entry> <key>keyValue</key> <value>0</value> </entry> </map>
- new NamedMapConverter(xstream.getMapper(), null, "key", String.class, "value",
Integer.class);
<map> <key>keyValue</key> <value>0</value> </map>
- new NamedMapConverter(xstream.getMapper(), "entry", "key", String.class, "value",
Integer.class, true, true, xstream.getConverterLookup());
<map> <entry> key="keyValue" value="0"/> </map>
- new NamedMapConverter(xstream.getMapper(), "entry", "key", String.class, "value",
Integer.class, true, false, xstream.getConverterLookup());
<map> <entry key="keyValue"> <value>0</value> </entry> </map>
- new NamedMapConverter(xstream.getMapper(), "entry", "key", String.class, "value",
Integer.class, false, true, xstream.getConverterLookup());
<map> <entry value="0"> <key>keyValue</key> </entry> </map>
- new NamedMapConverter(xstream.getMapper(), "entry", "key", String.class, null,
Integer.class, true, false, xstream.getConverterLookup());
<map> <entry key="keyValue">0</entry> </map>
- Since:
- 1.4.5
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String
entryName
private Mapper
enumMapper
private boolean
keyAsAttribute
private java.lang.String
keyName
private java.lang.Class
keyType
private ConverterLookup
lookup
private boolean
valueAsAttribute
private java.lang.String
valueName
private java.lang.Class
valueType
-
Constructor Summary
Constructors Constructor Description NamedMapConverter(Mapper mapper, java.lang.String entryName, java.lang.String keyName, java.lang.Class keyType, java.lang.String valueName, java.lang.Class valueType)
Constructs a NamedMapConverter.NamedMapConverter(Mapper mapper, java.lang.String entryName, java.lang.String keyName, java.lang.Class keyType, java.lang.String valueName, java.lang.Class valueType, boolean keyAsAttribute, boolean valueAsAttribute, ConverterLookup lookup)
Constructs a NamedMapConverter with attribute support.NamedMapConverter(java.lang.Class type, Mapper mapper, java.lang.String entryName, java.lang.String keyName, java.lang.Class keyType, java.lang.String valueName, java.lang.Class valueType)
Constructs a NamedMapConverter handling an explicit Map type.NamedMapConverter(java.lang.Class type, Mapper mapper, java.lang.String entryName, java.lang.String keyName, java.lang.Class keyType, java.lang.String valueName, java.lang.Class valueType, boolean keyAsAttribute, boolean valueAsAttribute, ConverterLookup lookup)
Constructs a NamedMapConverter with attribute support handling an explicit Map type.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private SingleValueConverter
getSingleValueConverter(java.lang.Class type, java.lang.String part)
void
marshal(java.lang.Object source, HierarchicalStreamWriter writer, MarshallingContext context)
Convert an object to textual data.protected void
populateMap(HierarchicalStreamReader reader, UnmarshallingContext context, java.util.Map map, java.util.Map target)
protected java.lang.Object
readItem(java.lang.Class type, HierarchicalStreamReader reader, UnmarshallingContext context, java.lang.Object current)
protected void
writeItem(java.lang.String name, java.lang.Class type, java.lang.Object item, MarshallingContext context, HierarchicalStreamWriter writer)
-
Methods inherited from class com.thoughtworks.xstream.converters.collections.MapConverter
canConvert, createCollection, populateMap, putCurrentEntryIntoMap, unmarshal
-
Methods inherited from class com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter
mapper, readBareItem, readCompleteItem, readItem, writeBareItem, writeCompleteItem, writeItem, writeNullItem
-
-
-
-
Field Detail
-
entryName
private final java.lang.String entryName
-
keyName
private final java.lang.String keyName
-
keyType
private final java.lang.Class keyType
-
valueName
private final java.lang.String valueName
-
valueType
private final java.lang.Class valueType
-
keyAsAttribute
private final boolean keyAsAttribute
-
valueAsAttribute
private final boolean valueAsAttribute
-
lookup
private final ConverterLookup lookup
-
enumMapper
private final Mapper enumMapper
-
-
Constructor Detail
-
NamedMapConverter
public NamedMapConverter(Mapper mapper, java.lang.String entryName, java.lang.String keyName, java.lang.Class keyType, java.lang.String valueName, java.lang.Class valueType)
Constructs a NamedMapConverter.- Parameters:
mapper
- the mapperentryName
- the name of the entry elementskeyName
- the name of the key elementskeyType
- the base type of key elementsvalueName
- the name of the value elementsvalueType
- the base type of value elements- Since:
- 1.4.5
-
NamedMapConverter
public NamedMapConverter(java.lang.Class type, Mapper mapper, java.lang.String entryName, java.lang.String keyName, java.lang.Class keyType, java.lang.String valueName, java.lang.Class valueType)
Constructs a NamedMapConverter handling an explicit Map type.- Parameters:
type
- the Map type this instance will handlemapper
- the mapperentryName
- the name of the entry elementskeyName
- the name of the key elementskeyType
- the base type of key elementsvalueName
- the name of the value elementsvalueType
- the base type of value elements- Since:
- 1.4.5
-
NamedMapConverter
public NamedMapConverter(Mapper mapper, java.lang.String entryName, java.lang.String keyName, java.lang.Class keyType, java.lang.String valueName, java.lang.Class valueType, boolean keyAsAttribute, boolean valueAsAttribute, ConverterLookup lookup)
Constructs a NamedMapConverter with attribute support.- Parameters:
mapper
- the mapperentryName
- the name of the entry elementskeyName
- the name of the key elementskeyType
- the base type of key elementsvalueName
- the name of the value elementsvalueType
- the base type of value elementskeyAsAttribute
- flag to write key as attribute of entry elementvalueAsAttribute
- flag to write value as attribute of entry elementlookup
- used to lookup SingleValueConverter for attributes- Since:
- 1.4.5
-
NamedMapConverter
public NamedMapConverter(java.lang.Class type, Mapper mapper, java.lang.String entryName, java.lang.String keyName, java.lang.Class keyType, java.lang.String valueName, java.lang.Class valueType, boolean keyAsAttribute, boolean valueAsAttribute, ConverterLookup lookup)
Constructs a NamedMapConverter with attribute support handling an explicit Map type.- Parameters:
type
- the Map type this instance will handlemapper
- the mapperentryName
- the name of the entry elementskeyName
- the name of the key elementskeyType
- the base type of key elementsvalueName
- the name of the value elementsvalueType
- the base type of value elementskeyAsAttribute
- flag to write key as attribute of entry elementvalueAsAttribute
- flag to write value as attribute of entry elementlookup
- used to lookup SingleValueConverter for attributes- Since:
- 1.4.5
-
-
Method Detail
-
marshal
public void marshal(java.lang.Object source, HierarchicalStreamWriter writer, MarshallingContext context)
Description copied from interface:Converter
Convert an object to textual data.- Specified by:
marshal
in interfaceConverter
- Overrides:
marshal
in classMapConverter
- Parameters:
source
- The object to be marshalled.writer
- A stream to write to.context
- A context that allows nested objects to be processed by XStream.
-
populateMap
protected void populateMap(HierarchicalStreamReader reader, UnmarshallingContext context, java.util.Map map, java.util.Map target)
- Overrides:
populateMap
in classMapConverter
-
getSingleValueConverter
private SingleValueConverter getSingleValueConverter(java.lang.Class type, java.lang.String part)
-
writeItem
protected void writeItem(java.lang.String name, java.lang.Class type, java.lang.Object item, MarshallingContext context, HierarchicalStreamWriter writer)
-
readItem
protected java.lang.Object readItem(java.lang.Class type, HierarchicalStreamReader reader, UnmarshallingContext context, java.lang.Object current)
-
-