public class MapConverter extends AbstractCollectionConverter
Note: 'key' and 'value' is not the name of the generated tag. The children are serialized as normal elements and the implementation expects them in the order 'key'/'value'.
Supports java.util.HashMap, java.util.Hashtable, java.util.LinkedHashMap and java.util.concurrent.ConcurrentHashMap.
Constructor and Description |
---|
MapConverter(Mapper mapper) |
MapConverter(Mapper mapper,
java.lang.Class type)
Construct a MapConverter for a special Map type.
|
Modifier and Type | Method and Description |
---|---|
boolean |
canConvert(java.lang.Class type)
Determines whether the converter can marshall a particular type.
|
protected java.lang.Object |
createCollection(java.lang.Class type) |
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) |
protected void |
populateMap(HierarchicalStreamReader reader,
UnmarshallingContext context,
java.util.Map map,
java.util.Map target) |
protected void |
putCurrentEntryIntoMap(HierarchicalStreamReader reader,
UnmarshallingContext context,
java.util.Map map,
java.util.Map target) |
java.lang.Object |
unmarshal(HierarchicalStreamReader reader,
UnmarshallingContext context)
Convert textual data back into an object.
|
mapper, readBareItem, readCompleteItem, readItem, writeBareItem, writeCompleteItem, writeItem, writeNullItem
public MapConverter(Mapper mapper)
public MapConverter(Mapper mapper, java.lang.Class type)
mapper
- the mappertype
- the type to handlepublic boolean canConvert(java.lang.Class type)
ConverterMatcher
canConvert
in interface ConverterMatcher
canConvert
in class AbstractCollectionConverter
type
- the Class representing the object type to be convertedpublic void marshal(java.lang.Object source, HierarchicalStreamWriter writer, MarshallingContext context)
Converter
marshal
in interface Converter
marshal
in class AbstractCollectionConverter
source
- The object to be marshalled.writer
- A stream to write to.context
- A context that allows nested objects to be processed by XStream.public java.lang.Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context)
Converter
unmarshal
in interface Converter
unmarshal
in class AbstractCollectionConverter
reader
- The stream to read the text from.protected void populateMap(HierarchicalStreamReader reader, UnmarshallingContext context, java.util.Map map)
protected void populateMap(HierarchicalStreamReader reader, UnmarshallingContext context, java.util.Map map, java.util.Map target)
protected void putCurrentEntryIntoMap(HierarchicalStreamReader reader, UnmarshallingContext context, java.util.Map map, java.util.Map target)
protected java.lang.Object createCollection(java.lang.Class type)
createCollection
in class AbstractCollectionConverter
Copyright © 2004–2024 XStream. All rights reserved.