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
    • Field Detail

      • entryName

        private final java.lang.String entryName
      • keyName

        private final java.lang.String keyName
      • keyType

        private final java.lang.Class keyType
      • valueName

        private final java.lang.String valueName
      • valueType

        private final java.lang.Class valueType
      • keyAsAttribute

        private final boolean keyAsAttribute
      • valueAsAttribute

        private final boolean valueAsAttribute
      • enumMapper

        private final Mapper enumMapper
    • Constructor Detail

      • NamedMapConverter

        public 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.
        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​(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.
        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,
                                 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.
        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​(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.
        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