public class NamedMapConverter extends MapConverter
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:
<map> <entry> <key>keyValue</key> <value>0</value> </entry> </map>
<map> <key>keyValue</key> <value>0</value> </map>
<map> <entry> key="keyValue" value="0"/> </map>
<map> <entry key="keyValue"> <value>0</value> </entry> </map>
<map> <entry value="0"> <key>keyValue</key> </entry> </map>
<map> <entry key="keyValue">0</entry> </map>
Constructor and Description |
---|
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.
|
NamedMapConverter(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.
|
Modifier and Type | Method and Description |
---|---|
void |
marshal(Object source,
HierarchicalStreamWriter writer,
MarshallingContext context)
Convert an object to textual data.
|
protected void |
populateMap(HierarchicalStreamReader reader,
UnmarshallingContext context,
Map map,
Map target) |
protected Object |
readItem(Class type,
HierarchicalStreamReader reader,
UnmarshallingContext context,
Object current) |
protected void |
writeItem(String name,
Class type,
Object item,
MarshallingContext context,
HierarchicalStreamWriter writer) |
canConvert, createCollection, populateMap, putCurrentEntryIntoMap, unmarshal
mapper, readItem, writeItem
public NamedMapConverter(Mapper mapper, String entryName, String keyName, Class keyType, String valueName, Class valueType)
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 elementspublic NamedMapConverter(Class type, Mapper mapper, String entryName, String keyName, Class keyType, String valueName, Class valueType)
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 elementspublic NamedMapConverter(Mapper mapper, String entryName, String keyName, Class keyType, String valueName, Class valueType, boolean keyAsAttribute, boolean valueAsAttribute, ConverterLookup lookup)
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 attributespublic NamedMapConverter(Class type, Mapper mapper, String entryName, String keyName, Class keyType, String valueName, Class valueType, boolean keyAsAttribute, boolean valueAsAttribute, ConverterLookup lookup)
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 attributespublic void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context)
Converter
marshal
in interface Converter
marshal
in class MapConverter
source
- The object to be marshalled.writer
- A stream to write to.context
- A context that allows nested objects to be processed by XStream.protected void populateMap(HierarchicalStreamReader reader, UnmarshallingContext context, Map map, Map target)
populateMap
in class MapConverter
protected void writeItem(String name, Class type, Object item, MarshallingContext context, HierarchicalStreamWriter writer)
protected Object readItem(Class type, HierarchicalStreamReader reader, UnmarshallingContext context, Object current)
Copyright © 2004–2017 XStream. All rights reserved.