Class 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
Author:
Jörg Schaible
  • Constructor Details

    • NamedMapConverter

      public NamedMapConverter(Mapper mapper, String entryName, String keyName, Class keyType, String valueName, Class valueType)
      Constructs a NamedMapConverter.
      Parameters:
      mapper - the mapper
      entryName - the name of the entry elements
      keyName - the name of the key elements
      keyType - the base type of key elements
      valueName - the name of the value elements
      valueType - 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 handle
      mapper - the mapper
      entryName - the name of the entry elements
      keyName - the name of the key elements
      keyType - the base type of key elements
      valueName - the name of the value elements
      valueType - 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 mapper
      entryName - the name of the entry elements
      keyName - the name of the key elements
      keyType - the base type of key elements
      valueName - the name of the value elements
      valueType - the base type of value elements
      keyAsAttribute - flag to write key as attribute of entry element
      valueAsAttribute - flag to write value as attribute of entry element
      lookup - 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 handle
      mapper - the mapper
      entryName - the name of the entry elements
      keyName - the name of the key elements
      keyType - the base type of key elements
      valueName - the name of the value elements
      valueType - the base type of value elements
      keyAsAttribute - flag to write key as attribute of entry element
      valueAsAttribute - flag to write value as attribute of entry element
      lookup - used to lookup SingleValueConverter for attributes
      Since:
      1.4.5
  • Method Details