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
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 -
Constructor Summary
ConstructorsConstructorDescriptionNamedMapConverter(Mapper mapper, String entryName, String keyName, Class keyType, String valueName, Class valueType) Constructs a NamedMapConverter.NamedMapConverter(Mapper mapper, String entryName, String keyName, Class keyType, String valueName, Class valueType, boolean keyAsAttribute, boolean valueAsAttribute, ConverterLookup lookup) Constructs a NamedMapConverter with attribute support.NamedMapConverter(Class type, Mapper mapper, String entryName, String keyName, Class keyType, String valueName, Class valueType) Constructs a NamedMapConverter handling an explicit Map type.NamedMapConverter(Class type, Mapper mapper, String entryName, String keyName, Class keyType, String valueName, Class valueType, boolean keyAsAttribute, boolean valueAsAttribute, ConverterLookup lookup) Constructs a NamedMapConverter with attribute support handling an explicit Map type. -
Method Summary
Modifier and TypeMethodDescriptionprivate SingleValueConvertergetSingleValueConverter(Class type, String part) voidmarshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) Convert an object to textual data.protected voidpopulateMap(HierarchicalStreamReader reader, UnmarshallingContext context, Map map, Map target) protected ObjectreadItem(Class type, HierarchicalStreamReader reader, UnmarshallingContext context, Object current) protected voidwriteItem(String name, Class type, Object item, MarshallingContext context, HierarchicalStreamWriter writer) Methods inherited from class MapConverter
canConvert, createCollection, populateMap, putCurrentEntryIntoMap, unmarshalMethods inherited from class AbstractCollectionConverter
mapper, readBareItem, readCompleteItem, readItem, writeBareItem, writeCompleteItem, writeItem, writeNullItem
-
Field Details
-
entryName
-
keyName
-
keyType
-
valueName
-
valueType
-
keyAsAttribute
private final boolean keyAsAttribute -
valueAsAttribute
private final boolean valueAsAttribute -
lookup
-
enumMapper
-
-
Constructor Details
-
NamedMapConverter
public NamedMapConverter(Mapper mapper, String entryName, String keyName, Class keyType, String valueName, 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(Class type, Mapper mapper, String entryName, String keyName, Class keyType, String valueName, 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, String entryName, String keyName, Class keyType, String valueName, 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(Class type, Mapper mapper, String entryName, String keyName, Class keyType, String valueName, 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 Details
-
marshal
Description copied from interface:ConverterConvert an object to textual data.- Specified by:
marshalin interfaceConverter- Overrides:
marshalin 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, Map map, Map target) - Overrides:
populateMapin classMapConverter
-
getSingleValueConverter
-
writeItem
protected void writeItem(String name, Class type, Object item, MarshallingContext context, HierarchicalStreamWriter writer) -
readItem
protected Object readItem(Class type, HierarchicalStreamReader reader, UnmarshallingContext context, Object current)
-