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(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.
|
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.
|
Modifier and Type | Method and Description |
---|---|
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) |
canConvert, createCollection, populateMap, putCurrentEntryIntoMap, unmarshal
mapper, readBareItem, readCompleteItem, readItem, writeBareItem, writeCompleteItem, writeItem, writeNullItem
public NamedMapConverter(Mapper mapper, java.lang.String entryName, java.lang.String keyName, java.lang.Class keyType, java.lang.String valueName, java.lang.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(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)
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, 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)
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(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)
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(java.lang.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, java.util.Map map, java.util.Map target)
populateMap
in class MapConverter
protected void writeItem(java.lang.String name, java.lang.Class type, java.lang.Object item, MarshallingContext context, HierarchicalStreamWriter writer)
protected java.lang.Object readItem(java.lang.Class type, HierarchicalStreamReader reader, UnmarshallingContext context, java.lang.Object current)
Copyright © 2004–2022 XStream. All rights reserved.