Class MarshalledMap

java.lang.Object
java.util.AbstractMap<K,V>
java.util.HashMap<K,V>
java.util.LinkedHashMap<String,Object>
org.apache.juneau.marshall.collections.MarshalledMap
All Implemented Interfaces:
Serializable, Cloneable, Map<String,Object>
Direct Known Subclasses:
Json5Map, JsonMap, ResolvingMarshalledMap

Neutral, marshaller-agnostic map of string-to-object entries.

This class is the base for JsonMap and the per-marshaller XMap variants. It carries all marshaller-neutral functionality such as typed accessors, fluent setters, bean integration, and PathTraversal-based path navigation. The default AbstractMap.toString() comes from LinkedHashMap; subclasses should override it to produce the appropriate marshalled form.

Note that the use of this class is optional. The serializers will accept any objects that implement the Map interface. But this class provides useful additional functionality when working with data models constructed from Java Collections Framework objects.

Notes:
  • This class is not thread safe.
See Also:
  • Field Details

  • Constructor Details

    • MarshalledMap

      public MarshalledMap()
      Construct an empty map.
    • MarshalledMap

      Construct an empty map with the specified bean context.
      Parameters:
      session - The bean session to use for creating beans.
    • MarshalledMap

      Construct a map initialized by parsing the specified string with the specified parser.
      Parameters:
      in - The input being parsed.
      Can be null or empty (results in an empty map; no parsing occurs).
      p - The parser to use to parse the input.
      Must not be null.
      Throws:
      ParseException - Malformed input encountered.
    • MarshalledMap

      public MarshalledMap(Map<?,?> in)
      Construct a map initialized with the specified map.
      Parameters:
      in - The map to copy.
      Can be null (results in an empty map).
      Keys will be converted to strings using Object.toString().
    • MarshalledMap

      public MarshalledMap(Object... keyValuePairs)
      Construct a map initialized with the specified key/value pairs.
      Parameters:
      keyValuePairs - A list of key/value pairs to add to this map.
    • MarshalledMap

      public MarshalledMap(Reader in, Parser p) throws ParseException
      Construct a map initialized by parsing the specified reader with the specified parser.
      Parameters:
      in - The reader containing the input being parsed.
      p - The parser to use to parse the input.
      Must not be null.
      Throws:
      ParseException - Malformed input encountered.
  • Method Details

    • create

      public static MarshalledMap create()
      Construct an empty map.
      Returns:
      An empty map.
    • filteredMap

      public static MarshalledMap filteredMap()
      Construct an empty filtered map.
      Returns:
      An empty map.
    • filteredMap

      public static MarshalledMap filteredMap(Object... keyValuePairs)
      Construct a filtered map initialized with the specified key/value pairs.
      Parameters:
      keyValuePairs - A list of key/value pairs to add to this map.
      Returns:
      A new map, never null.
    • of

      public static MarshalledMap of(Map<?,?> values)
      Construct a map initialized with the specified map.
      Parameters:
      values - The map to copy.
      Can be null (returns null).
      Keys will be converted to strings using Object.toString().
      Returns:
      A new map or null if the map was null.
    • of

      public static MarshalledMap of(Object... keyValuePairs)
      Construct a map initialized with the specified key/value pairs.
      Parameters:
      keyValuePairs - A list of key/value pairs to add to this map.
      Returns:
      A new map, never null.
    • ofString

      public static MarshalledMap ofString(CharSequence in, Parser p) throws ParseException
      Construct a map initialized by parsing the specified string with the specified parser.
      Parameters:
      in - The input being parsed.
      p - The parser to use to parse the input.
      Must not be null.
      Returns:
      A new map (empty if the input was null), never null.
      Throws:
      ParseException - Malformed input encountered.
    • ofString

      public static MarshalledMap ofString(Reader in, Parser p) throws ParseException
      Construct a map initialized by parsing the specified reader with the specified parser.
      Parameters:
      in - The reader containing the input being parsed.
      p - The parser to use to parse the input.
      Must not be null.
      Returns:
      A new map (empty if the input was null), never null.
      Throws:
      ParseException - Malformed input encountered.
    • append

      public MarshalledMap append(Map<String,Object> values)
      Appends all the entries in the specified map to this map.
      Parameters:
      values - The map to copy. Can be null (no-op).
      Returns:
      This object.
    • append

      public MarshalledMap append(String key, Object value)
      Adds an entry to this map.
      Parameters:
      key - The key.
      value - The value.
      Returns:
      This object.
    • appendFirst

      public <T> MarshalledMap appendFirst(Predicate<T> test, String key, T... values)
      Adds the first value that matches the specified predicate.
      Type Parameters:
      T - The value types.
      Parameters:
      test - The predicate to match against.
      key - The key.
      values - The values to test.
      Returns:
      This object.
    • appendIf

      public MarshalledMap appendIf(boolean flag, String key, Object value)
      Add if flag is true.
      Parameters:
      flag - The flag to check.
      key - The key.
      value - The value.
      Returns:
      This object.
    • appendIf

      public <T> MarshalledMap appendIf(Predicate<T> test, String key, T value)
      Add if predicate matches value.
      Type Parameters:
      T - The value type.
      Parameters:
      test - The predicate to match against.
      key - The key.
      value - The value.
      Returns:
      This object.
    • appendIfAbsent

      public MarshalledMap appendIfAbsent(String key, Object value)
      Adds a value in this map if the entry does not exist or the current value is null.
      Parameters:
      key - The map key.
      value - The value to set if the current value does not exist or is null.
      Returns:
      This object.
    • appendIfAbsentIf

      public <T> MarshalledMap appendIfAbsentIf(Predicate<T> predicate, String key, T value)
      Adds a value in this map if the entry does not exist or the current value is null and the value matches the specified predicate.
      Type Parameters:
      T - The value type.
      Parameters:
      predicate - The predicate to test the value with.
      key - The map key.
      value - The value to set if the current value does not exist or is null.
      Returns:
      This object.
    • at

      public MarshalledNode at(String pointer)
      Returns the node addressed by the specified RFC 6901 JSON Pointer relative to this map.

      Convenience for MarshalledNode.of(this).at(pointer). A read-miss returns null; an addressed JSON null value returns a null node.

      Beta — API subject to change: This method is part of the next-generation typed tree model layered over the Marshalled* collections and may change incompatibly in a future release.

      Parameters:
      pointer - The RFC 6901 JSON Pointer.
      Returns:
      A node wrapping the addressed value, or null if the addressed value is absent.
    • toString

      public String toString(WriterSerializer serializer)
      Serializes this map to a string using the specified serializer.
      Parameters:
      serializer - The serializer to use to convert this object to a string.
      Returns:
      This object serialized as a string.
    • cast

      public <T> T cast(Class<T> type)
      Converts this map into an object of the specified type.

      If this map contains a "_type" entry, it must be the same as or a subclass of the type.

      Type Parameters:
      T - The class type to convert this map object to.
      Parameters:
      type - The class type to convert this map object to.
      Returns:
      The new object.
      Throws:
      ClassCastException - If the "_type" entry is present and not assignable from type
    • cast

      public <T> T cast(ClassMeta<T> cm)
      Same as cast(Class), except allows you to specify a ClassMeta parameter.
      Type Parameters:
      T - The class type to convert this map object to.
      Parameters:
      cm - The class type to convert this map object to.
      Returns:
      The new object.
      Throws:
      ClassCastException - If the "_type" entry is present and not assignable from type
    • containsKey

      public boolean containsKey(Object key)
      Specified by:
      containsKey in interface Map<String,Object>
      Overrides:
      containsKey in class HashMap<String,Object>
    • containsKeyNotEmpty

      public boolean containsKeyNotEmpty(String key)
      Returns true if the map contains the specified entry and the value is not null nor an empty string.

      Always returns false if the value is not a CharSequence.

      Parameters:
      key - The key.
      Returns:
      true if the map contains the specified entry and the value is not null nor an empty string.
    • containsOuterKey

      public boolean containsOuterKey(Object key)
      Returns true if this map contains the specified key, ignoring the inner map if it exists.
      Parameters:
      key - The key to look up.
      Returns:
      true if this map contains the specified key.
    • deleteAt

      public Object deleteAt(String path)
      Similar to remove(Object), but the key is a slash-delimited path used to traverse entries in this POJO.

      This method uses the PathTraversal class to perform the lookup, so the map can contain any of the various class types that the PathTraversal class supports (e.g. beans, collections, arrays).

      Parameters:
      path - The path to the entry.
      Returns:
      The previous value, or null if the entry doesn't exist.
    • entrySet

      Specified by:
      entrySet in interface Map<String,Object>
      Overrides:
      entrySet in class LinkedHashMap<String,Object>
    • exclude

      public MarshalledMap exclude(String... keys)
      Returns a copy of this map without the specified keys.
      Parameters:
      keys - The keys of the entries not to copy.
      Returns:
      A new map without the keys and values from this map.
    • filtered

      Enables filtering based on default values.

      Any of the following types will be ignored when set as values in this map:

      • null
      • false
      • -1 (any Number type)
      • Empty arrays/collections/maps.
      Returns:
      This object.
    • filtered

      Enables filtering based on a predicate test.

      If the predicate evaluates to false on values added to this map, the entry will be skipped.

      Parameters:
      value - The value tester predicate.
      Returns:
      This object.
    • find

      public <T> T find(Class<T> type, String... keys)
      Returns the value for the first key in the list that has an entry in this map.

      Casts or converts the value to the specified class type.

      See MarshallingSession.convertToType(Object, ClassMeta) for the list of valid data conversions.

      Type Parameters:
      T - The class type to convert the value to.
      Parameters:
      type - The class type to convert the value to.
      keys - The keys to look up in order.
      Returns:
      The value of the first entry whose key exists, or null if none of the keys exist in this map.
    • find

      public Object find(String... keys)
      Returns the value for the first key in the list that has an entry in this map.
      Parameters:
      keys - The keys to look up in order.
      Returns:
      The value of the first entry whose key exists, or null if none of the keys exist in this map.
    • findBoolean

      public Boolean findBoolean(String... keys)
      Returns the first entry that exists converted to a Boolean.
      Parameters:
      keys - The list of keys to look for.
      Returns:
      The converted value of the first key in the list that has an entry in this map, or null if the map contains no mapping for any of the keys.
      Throws:
      InvalidDataConversionException - If value cannot be converted.
    • findInt

      public Integer findInt(String... keys)
      Returns the first entry that exists converted to an Integer.
      Parameters:
      keys - The list of keys to look for.
      Returns:
      The converted value of the first key in the list that has an entry in this map, or null if the map contains no mapping for any of the keys.
      Throws:
      InvalidDataConversionException - If value cannot be converted.
    • findKeyIgnoreCase

      Searches for the specified key in this map ignoring case.
      Parameters:
      key - The key to search for. For performance reasons, it's preferable that the key be all lowercase.
      Returns:
      The key, or null if map does not contain this key.
    • findList

      public MarshalledList findList(String... keys)
      Returns the first entry that exists converted to a MarshalledList.
      Parameters:
      keys - The list of keys to look for.
      Returns:
      The converted value of the first key in the list that has an entry in this map, or null if the map contains no mapping for any of the keys.
      Throws:
      InvalidDataConversionException - If value cannot be converted.
    • findLong

      public Long findLong(String... keys)
      Returns the first entry that exists converted to a Long.
      Parameters:
      keys - The list of keys to look for.
      Returns:
      The converted value of the first key in the list that has an entry in this map, or null if the map contains no mapping for any of the keys.
      Throws:
      InvalidDataConversionException - If value cannot be converted.
    • findMap

      public MarshalledMap findMap(String... keys)
      Returns the first entry that exists converted to a MarshalledMap.
      Parameters:
      keys - The list of keys to look for.
      Returns:
      The converted value of the first key in the list that has an entry in this map, or null if the map contains no mapping for any of the keys.
      Throws:
      InvalidDataConversionException - If value cannot be converted.
    • findString

      public String findString(String... keys)
      Returns the first entry that exists converted to a String.
      Parameters:
      keys - The list of keys to look for.
      Returns:
      The converted value of the first key in the list that has an entry in this map, or null if the map contains no mapping for any of the keys.
    • get

      public Object get(Object key)
      Specified by:
      get in interface Map<String,Object>
      Overrides:
      get in class LinkedHashMap<String,Object>
    • get

      public <T> T get(String key, Class<T> type)
      Same as get(), but casts or converts the value to the specified class type.

      See MarshallingSession.convertToType(Object, ClassMeta) for the list of valid data conversions.

      Type Parameters:
      T - The class type returned.
      Parameters:
      key - The key.
      type - The class type returned.
      Returns:
      The value, or null if the entry doesn't exist.
    • get

      public <T> T get(String key, Type type, Type... args)
      Same as get(String,Class), but allows for complex data types consisting of collections or maps.

      The type can be a simple type (e.g. beans, strings, numbers) or parameterized type (collections/maps).

      See MarshallingSession.convertToType(Object, ClassMeta) for the list of valid data conversions.

      Type Parameters:
      T - The class type returned.
      Parameters:
      key - The key.
      type - The class type returned.
      args - The class type parameters.
      Returns:
      The value, or null if the entry doesn't exist.
    • getAt

      public <T> T getAt(String path, Class<T> type)
      Same as get(String,Class), but the key is a slash-delimited path used to traverse entries in this POJO.
      Type Parameters:
      T - The class type.
      Parameters:
      path - The path to the entry.
      type - The class type.
      Returns:
      The value, or null if the entry doesn't exist.
    • getAt

      public <T> T getAt(String path, Type type, Type... args)
      Same as getAt(String,Class), but allows for conversion to complex maps and collections.
      Type Parameters:
      T - The class type.
      Parameters:
      path - The path to the entry.
      type - The class type.
      args - The class parameter types.
      Returns:
      The value, or null if the entry doesn't exist.
    • getBoolean

      public Boolean getBoolean(String key)
      Returns the specified entry value converted to a Boolean.
      Parameters:
      key - The key.
      Returns:
      The converted value, or null if the map contains no mapping for this key.
      Throws:
      InvalidDataConversionException - If value cannot be converted.
    • getBoolean

      public Boolean getBoolean(String key, Boolean defVal)
      Returns the specified entry value converted to a Boolean.
      Parameters:
      key - The key.
      defVal - The default value if the map doesn't contain the specified mapping.
      Returns:
      The converted value, or the default value if the map contains no mapping for this key.
      Throws:
      InvalidDataConversionException - If value cannot be converted.
    • getClassMeta

      public ClassMeta<?> getClassMeta(String key)
      Returns the class type of the object at the specified index.
      Parameters:
      key - The key into this map.
      Returns:
      The data type of the object at the specified key, or null if the value is null or does not exist.
    • getFirstKey

      public String getFirstKey()
      Returns the first key in the map.
      Returns:
      The first key in the map, or null if the map is empty.
    • getInt

      public Integer getInt(String key)
      Returns the specified entry value converted to an Integer.
      Parameters:
      key - The key.
      Returns:
      The converted value, or null if the map contains no mapping for this key.
      Throws:
      InvalidDataConversionException - If value cannot be converted.
    • getInt

      public Integer getInt(String key, Integer defVal)
      Returns the specified entry value converted to an Integer.
      Parameters:
      key - The key.
      defVal - The default value if the map doesn't contain the specified mapping.
      Returns:
      The converted value, or the default value if the map contains no mapping for this key.
      Throws:
      InvalidDataConversionException - If value cannot be converted.
    • getList

      Returns the specified entry value converted to a MarshalledList.
      Parameters:
      key - The key.
      Returns:
      The converted value, or null if the map contains no mapping for this key.
      Throws:
      InvalidDataConversionException - If value cannot be converted.
    • getList

      public MarshalledList getList(String key, boolean createIfNotExists)
      Same as getList(String) but creates a new empty MarshalledList if it doesn't already exist.
      Parameters:
      key - The key.
      createIfNotExists - If mapping doesn't already exist, create one with an empty MarshalledList.
      Returns:
      The converted value, or an empty value if the map contains no mapping for this key.
      Throws:
      InvalidDataConversionException - If value cannot be converted.
    • getList

      public <E> List<E> getList(String key, Class<E> elementType, List<E> def)
      Same as getList(String, MarshalledList) except converts the elements to the specified types.
      Type Parameters:
      E - The element type.
      Parameters:
      key - The key.
      elementType - The element type class.
      def - The default value if the map doesn't contain the specified mapping.
      Returns:
      The converted value, or the default value if the map contains no mapping for this key.
      Throws:
      InvalidDataConversionException - If value cannot be converted.
    • getList

      Returns the specified entry value converted to a MarshalledList.
      Parameters:
      key - The key.
      defVal - The default value if the map doesn't contain the specified mapping.
      Returns:
      The converted value, or the default value if the map contains no mapping for this key.
      Throws:
      InvalidDataConversionException - If value cannot be converted.
    • getLong

      public Long getLong(String key)
      Returns the specified entry value converted to a Long.
      Parameters:
      key - The key.
      Returns:
      The converted value, or null if the map contains no mapping for this key.
      Throws:
      InvalidDataConversionException - If value cannot be converted.
    • getLong

      public Long getLong(String key, Long defVal)
      Returns the specified entry value converted to a Long.
      Parameters:
      key - The key.
      defVal - The default value if the map doesn't contain the specified mapping.
      Returns:
      The converted value, or the default value if the map contains no mapping for this key.
      Throws:
      InvalidDataConversionException - If value cannot be converted.
    • getMap

      public MarshalledMap getMap(String key)
      Returns the specified entry value converted to a Map.
      Parameters:
      key - The key.
      Returns:
      The converted value, or null if the map contains no mapping for this key.
      Throws:
      InvalidDataConversionException - If value cannot be converted.
    • getMap

      public MarshalledMap getMap(String key, boolean createIfNotExists)
      Same as getMap(String) but creates a new empty MarshalledMap if it doesn't already exist.
      Parameters:
      key - The key.
      createIfNotExists - If mapping doesn't already exist, create one with an empty MarshalledMap.
      Returns:
      The converted value, or an empty value if the map contains no mapping for this key.
      Throws:
      InvalidDataConversionException - If value cannot be converted.
    • getMap

      public <K, V> Map<K,V> getMap(String key, Class<K> keyType, Class<V> valType, Map<K,V> def)
      Same as getMap(String, MarshalledMap) except converts the keys and values to the specified types.
      Type Parameters:
      K - The key type.
      V - The value type.
      Parameters:
      key - The key.
      keyType - The key type class.
      valType - The value type class.
      def - The default value if the map doesn't contain the specified mapping.
      Returns:
      The converted value, or the default value if the map contains no mapping for this key.
      Throws:
      InvalidDataConversionException - If value cannot be converted.
    • getMap

      public MarshalledMap getMap(String key, MarshalledMap defVal)
      Returns the specified entry value converted to a MarshalledMap.
      Parameters:
      key - The key.
      defVal - The default value if the map doesn't contain the specified mapping.
      Returns:
      The converted value, or the default value if the map contains no mapping for this key.
      Throws:
      InvalidDataConversionException - If value cannot be converted.
    • getMarshallingSession

      Returns the MarshallingSession currently associated with this map.
      Returns:
      The MarshallingSession currently associated with this map.
    • getString

      public String getString(String key)
      Returns the specified entry value converted to a String.
      Parameters:
      key - The key.
      Returns:
      The converted value, or null if the map contains no mapping for this key.
    • getString

      public String getString(String key, String defVal)
      Returns the specified entry value converted to a String.
      Parameters:
      key - The key.
      defVal - The default value if the map doesn't contain the specified mapping.
      Returns:
      The converted value, or the default value if the map contains no mapping for this key.
    • getStringArray

      public String[] getStringArray(String key)
      Returns the specified entry value converted to a String[] array.
      Parameters:
      key - The key.
      Returns:
      The converted value, or null if the map contains no mapping for this key.
    • getStringArray

      public String[] getStringArray(String key, String[] def)
      Same as getStringArray(String) but returns a default value if the value cannot be found.
      Parameters:
      key - The map key.
      def - The default value if value is not found.
      Returns:
      The value converted to a string array.
    • getSwapped

      public <T> T getSwapped(String key, ObjectSwap<T,?> objectSwap) throws ParseException
      Same as get(), but converts the raw value to the specified class type using the specified POJO swap.
      Type Parameters:
      T - The transformed class type.
      Parameters:
      key - The key.
      objectSwap - The swap class used to convert the raw type to a transformed type.
      Returns:
      The value, or null if the entry doesn't exist.
      Throws:
      ParseException - Malformed input encountered.
    • getWithDefault

      public Object getWithDefault(String key, Object def)
      Same as get(), but returns the default value if the key could not be found.
      Parameters:
      key - The key.
      def - The default value if the entry doesn't exist.
      Returns:
      The value, or the default value if the entry doesn't exist.
    • getWithDefault

      public <T> T getWithDefault(String key, T def, Class<T> type)
      Same as get(String,Class) but returns a default value if the value does not exist.
      Type Parameters:
      T - The class type returned.
      Parameters:
      key - The key.
      def - The default value. Can be null (returns null if the entry doesn't exist).
      type - The class type returned.
      Returns:
      The value, or null if the entry doesn't exist.
    • getWithDefault

      public <T> T getWithDefault(String key, T def, Type type, Type... args)
      Same as get(String,Type,Type...) but returns a default value if the value does not exist.
      Type Parameters:
      T - The class type returned.
      Parameters:
      key - The key.
      def - The default value. Can be null (returns null if the entry doesn't exist).
      type - The class type returned.
      args - The class type parameters.
      Returns:
      The value, or null if the entry doesn't exist.
    • include

      public MarshalledMap include(String... keys)
      Returns a copy of this map with only the specified keys.
      Parameters:
      keys - The keys of the entries to copy.
      Returns:
      A new map with just the keys and values from this map.
    • inner

      public MarshalledMap inner(Map<String,Object> inner)
      Set an inner map in this map to allow for chained get calls.

      If get(Object) returns null, then get(Object) will be called on the inner map.

      Parameters:
      inner - The inner map. Can be null to remove the inner map from an existing map.
      Returns:
      This object.
    • is

      public boolean is(String key, boolean defVal)
      Shortcut for getWithDefault(key, defVal, Boolean.class).
      Parameters:
      key - The key.
      defVal - The default value if the map doesn't contain the specified mapping.
      Returns:
      The converted value, or the default value if the map contains no mapping for this key.
      Throws:
      InvalidDataConversionException - If value cannot be converted.
    • isUnmodifiable

      public boolean isUnmodifiable()
      Returns true if this map is unmodifiable.
      Returns:
      true if this map is unmodifiable.
    • keepAll

      public MarshalledMap keepAll(String... keys)
      The opposite of removeAll(String...).

      Discards all keys from this map that aren't in the specified list.

      Parameters:
      keys - The keys to keep.
      Returns:
      This map.
    • keySet

      public Set<String> keySet()
      Specified by:
      keySet in interface Map<String,Object>
      Overrides:
      keySet in class LinkedHashMap<String,Object>
    • equals

      public boolean equals(Object o)
      Specified by:
      equals in interface Map<String,Object>
      Overrides:
      equals in class AbstractMap<String,Object>
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in interface Map<String,Object>
      Overrides:
      hashCode in class AbstractMap<String,Object>
    • modifiable

      Returns a modifiable copy of this map if it's unmodifiable.
      Returns:
      A modifiable copy of this map if it's unmodifiable, or this map if it is already modifiable.
    • postAt

      public Object postAt(String path, Object o)
      Similar to putAt(String,Object), but used to append to collections and arrays.

      This method uses the PathTraversal class to perform the lookup, so the map can contain any of the various class types that the PathTraversal class supports (e.g. beans, collections, arrays).

      Parameters:
      path - The path to the entry.
      o - The new value.
      Returns:
      The previous value, or null if the entry doesn't exist.
    • put

      public Object put(String key, Object value)
      Specified by:
      put in interface Map<String,Object>
      Overrides:
      put in class HashMap<String,Object>
    • putAt

      public Object putAt(String path, Object o)
      Same as put(String,Object), but the key is a slash-delimited path used to traverse entries in this POJO.

      This method uses the PathTraversal class to perform the lookup, so the map can contain any of the various class types that the PathTraversal class supports (e.g. beans, collections, arrays).

      Parameters:
      path - The path to the entry.
      o - The new value.
      Returns:
      The previous value, or null if the entry doesn't exist.
    • removeAll

      public void removeAll(Collection<String> keys)
      Convenience method for removing several keys at once.
      Parameters:
      keys - The list of keys to remove.
    • removeAll

      public void removeAll(String... keys)
      Convenience method for removing several keys at once.
      Parameters:
      keys - The list of keys to remove.
    • removeBoolean

      Equivalent to calling removeWithDefault(key,null,Boolean.class).
      Parameters:
      key - The key.
      Returns:
      The converted value, or null if the map contains no mapping for this key.
      Throws:
      InvalidDataConversionException - If value cannot be converted.
    • removeBoolean

      public Boolean removeBoolean(String key, Boolean def)
      Equivalent to calling removeWithDefault(key,def,Boolean.class).
      Parameters:
      key - The key.
      def - The default value if the map doesn't contain the specified mapping.
      Returns:
      The converted value, or the default value if the map contains no mapping for this key.
      Throws:
      InvalidDataConversionException - If value cannot be converted.
    • removeInt

      public Integer removeInt(String key)
      Equivalent to calling removeWithDefault(key,null,Integer.class).
      Parameters:
      key - The key.
      Returns:
      The converted value, or null if the map contains no mapping for this key.
      Throws:
      InvalidDataConversionException - If value cannot be converted.
    • removeInt

      public Integer removeInt(String key, Integer def)
      Equivalent to calling removeWithDefault(key,def,Integer.class).
      Parameters:
      key - The key.
      def - The default value if the map doesn't contain the specified mapping.
      Returns:
      The converted value, or the default value if the map contains no mapping for this key.
      Throws:
      InvalidDataConversionException - If value cannot be converted.
    • removeString

      public String removeString(String key)
      Equivalent to calling removeWithDefault(key,null,String.class).
      Parameters:
      key - The key.
      Returns:
      The converted value, or null if the map contains no mapping for this key.
      Throws:
      InvalidDataConversionException - If value cannot be converted.
    • removeString

      public String removeString(String key, String def)
      Equivalent to calling removeWithDefault(key,def,String.class).
      Parameters:
      key - The key.
      def - The default value if the map doesn't contain the specified mapping.
      Returns:
      The converted value, or the default value if the map contains no mapping for this key.
      Throws:
      InvalidDataConversionException - If value cannot be converted.
    • removeWithDefault

      public <T> T removeWithDefault(String key, T defVal, Class<T> type)
      Equivalent to calling get(class,key,def) followed by remove(key);
      Type Parameters:
      T - The class type.
      Parameters:
      key - The key.
      defVal - The default value if the map doesn't contain the specified mapping.
      type - The class type.
      Returns:
      The converted value, or the default value if the map contains no mapping for this key.
      Throws:
      InvalidDataConversionException - If value cannot be converted.
    • session

      Override the default bean session used for converting POJOs.

      Default is MarshallingContext.DEFAULT, which is sufficient in most cases.

      Useful if you're serializing/parsing beans with transforms defined.

      Parameters:
      session - The new bean session.
      Returns:
      This object.
    • setBeanSession

      Sets the MarshallingSession currently associated with this map.
      Parameters:
      value - The MarshallingSession currently associated with this map.
      Returns:
      This object.
    • unmodifiable

      Returns an unmodifiable copy of this map if it's modifiable.
      Returns:
      An unmodifiable copy of this map if it's modifiable, or this map if it is already unmodifiable.
    • bs

      protected MarshallingSession bs()
      Returns the MarshallingSession associated with this map (lazily defaults to MarshallingContext.DEFAULT_SESSION).
      Returns:
      The MarshallingSession for this map.
    • newMarshalledMap

      Factory hook used by cast(Class) / cast(ClassMeta) when the target map type cannot be instantiated directly (e.g. when the caller asks for the Map interface).

      Subclasses should override to return an instance of the matching XMap variant so that callers chaining off of cast(Map.class) still see their flavored map type.

      Parameters:
      bs - The marshalling session to associate with the new map.
      Returns:
      A new map instance.