Class MarshalledMap
- All Implemented Interfaces:
Serializable,Cloneable,Map<String,Object>
- Direct Known Subclasses:
Json5Map,JsonMap,ResolvingMarshalledMap
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:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object, V extends Object> -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionConstruct an empty map.MarshalledMap(Reader in, Parser p) Construct a map initialized by parsing the specified reader with the specified parser.MarshalledMap(CharSequence in, Parser p) Construct a map initialized by parsing the specified string with the specified parser.MarshalledMap(Object... keyValuePairs) Construct a map initialized with the specified key/value pairs.MarshalledMap(Map<?, ?> in) Construct a map initialized with the specified map.MarshalledMap(MarshallingSession session) Construct an empty map with the specified bean context. -
Method Summary
Modifier and TypeMethodDescriptionAdds an entry to this map.Appends all the entries in the specified map to this map.<T> MarshalledMapappendFirst(Predicate<T> test, String key, T... values) Adds the first value that matches the specified predicate.Add if flag istrue .<T> MarshalledMapAdd if predicate matches value.appendIfAbsent(String key, Object value) Adds a value in this map if the entry does not exist or the current value isnull .<T> MarshalledMapappendIfAbsentIf(Predicate<T> predicate, String key, T value) Adds a value in this map if the entry does not exist or the current value isnull and the value matches the specified predicate.Returns the node addressed by the specified RFC 6901 JSON Pointer relative to this map.protected MarshallingSessionbs()Returns theMarshallingSessionassociated with this map (lazily defaults toMarshallingContext.DEFAULT_SESSION).<T> TConverts this map into an object of the specified type.<T> TSame ascast(Class), except allows you to specify aClassMetaparameter.booleancontainsKey(Object key) booleanReturnstrue if the map contains the specified entry and the value is not null nor an empty string.booleancontainsOuterKey(Object key) Returnstrue if this map contains the specified key, ignoring the inner map if it exists.static MarshalledMapcreate()Construct an empty map.Similar toremove(Object), but the key is a slash-delimited path used to traverse entries in this POJO.entrySet()booleanReturns a copy of this map without the specified keys.filtered()Enables filtering based on default values.Enables filtering based on a predicate test.static MarshalledMapConstruct an empty filtered map.static MarshalledMapfilteredMap(Object... keyValuePairs) Construct a filtered map initialized with the specified key/value pairs.<T> TReturns the value for the first key in the list that has an entry in this map.Returns the value for the first key in the list that has an entry in this map.findBoolean(String... keys) Returns the first entry that exists converted to aBoolean.Returns the first entry that exists converted to anInteger.findKeyIgnoreCase(String key) Searches for the specified key in this map ignoring case.Returns the first entry that exists converted to aMarshalledList.Returns the first entry that exists converted to aLong.Returns the first entry that exists converted to aMarshalledMap.findString(String... keys) Returns the first entry that exists converted to aString.<T> TSame asget(), but casts or converts the value to the specified class type.<T> TSame asget(String,Class), but allows for complex data types consisting of collections or maps.<T> TSame asget(String,Class), but the key is a slash-delimited path used to traverse entries in this POJO.<T> TSame asgetAt(String,Class), but allows for conversion to complex maps and collections.getBoolean(String key) Returns the specified entry value converted to aBoolean.getBoolean(String key, Boolean defVal) Returns the specified entry value converted to aBoolean.ClassMeta<?>getClassMeta(String key) Returns the class type of the object at the specified index.Returns the first key in the map.Returns the specified entry value converted to anInteger.Returns the specified entry value converted to anInteger.Returns the specified entry value converted to aMarshalledList.Same asgetList(String)but creates a new emptyMarshalledListif it doesn't already exist.<E> List<E>Same asgetList(String, MarshalledList)except converts the elements to the specified types.getList(String key, MarshalledList defVal) Returns the specified entry value converted to aMarshalledList.Returns the specified entry value converted to aLong.Returns the specified entry value converted to aLong.Returns the specified entry value converted to aMap.Same asgetMap(String)but creates a new emptyMarshalledMapif it doesn't already exist.<K,V> Map<K, V> Same asgetMap(String, MarshalledMap)except converts the keys and values to the specified types.getMap(String key, MarshalledMap defVal) Returns the specified entry value converted to aMarshalledMap.Returns theMarshallingSessioncurrently associated with this map.Returns the specified entry value converted to aString.Returns the specified entry value converted to aString.String[]getStringArray(String key) Returns the specified entry value converted to aString[] array.String[]getStringArray(String key, String[] def) Same asgetStringArray(String)but returns a default value if the value cannot be found.<T> TgetSwapped(String key, ObjectSwap<T, ?> objectSwap) Same asget(), but converts the raw value to the specified class type using the specified POJO swap.getWithDefault(String key, Object def) Same asget(), but returns the default value if the key could not be found.<T> TgetWithDefault(String key, T def, Class<T> type) Same asget(String,Class)but returns a default value if the value does not exist.<T> TgetWithDefault(String key, T def, Type type, Type... args) Same asget(String,Type,Type...)but returns a default value if the value does not exist.inthashCode()Returns a copy of this map with only the specified keys.Set an inner map in this map to allow for chained get calls.booleanShortcut forgetWithDefault(key, defVal, Boolean..class )booleanReturnstrue if this map is unmodifiable.The opposite ofremoveAll(String...).keySet()Returns a modifiable copy of this map if it's unmodifiable.protected MarshalledMapFactory hook used bycast(Class)/cast(ClassMeta)when the target map type cannot be instantiated directly (e.g. when the caller asks for theMapinterface).static MarshalledMapConstruct a map initialized with the specified key/value pairs.static MarshalledMapConstruct a map initialized with the specified map.static MarshalledMapConstruct a map initialized by parsing the specified reader with the specified parser.static MarshalledMapofString(CharSequence in, Parser p) Construct a map initialized by parsing the specified string with the specified parser.Similar toputAt(String,Object), but used to append to collections and arrays.Same asput(String,Object) , but the key is a slash-delimited path used to traverse entries in this POJO.voidConvenience method for removing several keys at once.voidremoveAll(Collection<String> keys) Convenience method for removing several keys at once.removeBoolean(String key) Equivalent to callingremoveWithDefault(key,.null ,Boolean.class )removeBoolean(String key, Boolean def) Equivalent to callingremoveWithDefault(key,def,Boolean..class )Equivalent to callingremoveWithDefault(key,.null ,Integer.class )Equivalent to callingremoveWithDefault(key,def,Integer..class )removeString(String key) Equivalent to callingremoveWithDefault(key,.null ,String.class )removeString(String key, String def) Equivalent to callingremoveWithDefault(key,def,String..class )<T> TremoveWithDefault(String key, T defVal, Class<T> type) Equivalent to callingget(class,key,def) followed byremove(key); session(MarshallingSession session) Override the default bean session used for converting POJOs.setBeanSession(MarshallingSession value) Sets theMarshallingSessioncurrently associated with this map.toString(WriterSerializer serializer) Serializes this map to a string using the specified serializer.Returns an unmodifiable copy of this map if it's modifiable.Methods inherited from class java.util.LinkedHashMap
clear, containsValue, forEach, getOrDefault, removeEldestEntry, replaceAll, valuesMethods inherited from class java.util.HashMap
clone, compute, computeIfAbsent, computeIfPresent, isEmpty, merge, putAll, putIfAbsent, remove, remove, replace, replace, sizeMethods inherited from class java.util.AbstractMap
toStringMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, isEmpty, merge, putAll, putIfAbsent, remove, remove, replace, replace, size
-
Field Details
-
EMPTY_MAP
An empty read-only MarshalledMap.
-
-
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 benull or empty (results in an empty map; no parsing occurs).p- The parser to use to parse the input.
Must not benull .- Throws:
ParseException- Malformed input encountered.
-
MarshalledMap
Construct a map initialized with the specified map.- Parameters:
in- The map to copy.
Can benull (results in an empty map).
Keys will be converted to strings usingObject.toString().
-
MarshalledMap
Construct a map initialized with the specified key/value pairs.- Parameters:
keyValuePairs- A list of key/value pairs to add to this map.
-
MarshalledMap
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 benull .- Throws:
ParseException- Malformed input encountered.
-
-
Method Details
-
create
Construct an empty map.- Returns:
- An empty map.
-
filteredMap
Construct an empty filtered map.- Returns:
- An empty map.
-
filteredMap
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
Construct a map initialized with the specified map.- Parameters:
values- The map to copy.
Can benull (returnsnull ).
Keys will be converted to strings usingObject.toString().- Returns:
- A new map or
null if the map wasnull .
-
of
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
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 benull .- Returns:
- A new map (empty if the input was
null ), nevernull . - Throws:
ParseException- Malformed input encountered.
-
ofString
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 benull .- Returns:
- A new map (empty if the input was
null ), nevernull . - Throws:
ParseException- Malformed input encountered.
-
append
Appends all the entries in the specified map to this map.- Parameters:
values- The map to copy. Can benull (no-op).- Returns:
- This object.
-
append
Adds an entry to this map.- Parameters:
key- The key.value- The value.- Returns:
- This object.
-
appendFirst
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
Add if flag istrue .- Parameters:
flag- The flag to check.key- The key.value- The value.- Returns:
- This object.
-
appendIf
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
Adds a value in this map if the entry does not exist or the current value isnull .- Parameters:
key- The map key.value- The value to set if the current value does not exist or isnull .- Returns:
- This object.
-
appendIfAbsentIf
Adds a value in this map if the entry does not exist or the current value isnull 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 isnull .- Returns:
- This object.
-
at
Returns the node addressed by the specified RFC 6901 JSON Pointer relative to this map.Convenience for
MarshalledNode. . A read-miss returnsof (this ).at(pointer )null ; an addressed JSONnull 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
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
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 thetype .- 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 fromtype
-
cast
Same ascast(Class), except allows you to specify aClassMetaparameter.- 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 fromtype
-
containsKey
- Specified by:
containsKeyin interfaceMap<String,Object> - Overrides:
containsKeyin classHashMap<String,Object>
-
containsKeyNotEmpty
Returnstrue 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 aCharSequence.- Parameters:
key- The key.- Returns:
true if the map contains the specified entry and the value is not null nor an empty string.
-
containsOuterKey
Returnstrue 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
Similar toremove(Object), but the key is a slash-delimited path used to traverse entries in this POJO.This method uses the
PathTraversalclass to perform the lookup, so the map can contain any of the various class types that thePathTraversalclass 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
-
exclude
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
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
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
Returns the first entry that exists converted to aBoolean.- 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
Returns the first entry that exists converted to anInteger.- 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
Returns the first entry that exists converted to aMarshalledList.- 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
Returns the first entry that exists converted to aLong.- 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
Returns the first entry that exists converted to aMarshalledMap.- 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
Returns the first entry that exists converted to aString.- 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
-
get
Same asget(), 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
Same asget(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
Same asget(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
Same asgetAt(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
Returns the specified entry value converted to aBoolean.- 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
Returns the specified entry value converted to aBoolean.- 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
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
Returns the first key in the map.- Returns:
- The first key in the map, or
null if the map is empty.
-
getInt
Returns the specified entry value converted to anInteger.- 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
Returns the specified entry value converted to anInteger.- 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 aMarshalledList.- 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
Same asgetList(String)but creates a new emptyMarshalledListif it doesn't already exist.- Parameters:
key- The key.createIfNotExists- If mapping doesn't already exist, create one with an emptyMarshalledList.- 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
Same asgetList(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 aMarshalledList.- 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
Returns the specified entry value converted to aLong.- 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
Returns the specified entry value converted to aLong.- 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
Returns the specified entry value converted to aMap.- 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
Same asgetMap(String)but creates a new emptyMarshalledMapif it doesn't already exist.- Parameters:
key- The key.createIfNotExists- If mapping doesn't already exist, create one with an emptyMarshalledMap.- 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
Same asgetMap(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
Returns the specified entry value converted to aMarshalledMap.- 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 theMarshallingSessioncurrently associated with this map.- Returns:
- The
MarshallingSessioncurrently associated with this map.
-
getString
Returns the specified entry value converted to aString.- Parameters:
key- The key.- Returns:
- The converted value, or
null if the map contains no mapping for this key.
-
getString
Returns the specified entry value converted to aString.- 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
Returns the specified entry value converted to aString[] array.- Parameters:
key- The key.- Returns:
- The converted value, or
null if the map contains no mapping for this key.
-
getStringArray
Same asgetStringArray(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
Same asget(), 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
Same asget(), 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
Same asget(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 benull (returnsnull if the entry doesn't exist).type- The class type returned.- Returns:
- The value, or
null if the entry doesn't exist.
-
getWithDefault
Same asget(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 benull (returnsnull 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
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
Set an inner map in this map to allow for chained get calls.If
get(Object)returnsnull , thenget(Object)will be called on the inner map.- Parameters:
inner- The inner map. Can benull to remove the inner map from an existing map.- Returns:
- This object.
-
is
Shortcut forgetWithDefault(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
Returnstrue if this map is unmodifiable.- Returns:
true if this map is unmodifiable.
-
keepAll
The opposite ofremoveAll(String...).Discards all keys from this map that aren't in the specified list.
- Parameters:
keys- The keys to keep.- Returns:
- This map.
-
keySet
-
equals
-
hashCode
-
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
Similar toputAt(String,Object), but used to append to collections and arrays.This method uses the
PathTraversalclass to perform the lookup, so the map can contain any of the various class types that thePathTraversalclass 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
-
putAt
Same asput(String,Object) , but the key is a slash-delimited path used to traverse entries in this POJO.This method uses the
PathTraversalclass to perform the lookup, so the map can contain any of the various class types that thePathTraversalclass 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
Convenience method for removing several keys at once.- Parameters:
keys- The list of keys to remove.
-
removeAll
Convenience method for removing several keys at once.- Parameters:
keys- The list of keys to remove.
-
removeBoolean
Equivalent to callingremoveWithDefault(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
Equivalent to callingremoveWithDefault(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
Equivalent to callingremoveWithDefault(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
Equivalent to callingremoveWithDefault(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
Equivalent to callingremoveWithDefault(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
Equivalent to callingremoveWithDefault(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
Equivalent to callingget(class,key,def) followed byremove(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 theMarshallingSessioncurrently associated with this map.- Parameters:
value- TheMarshallingSessioncurrently 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
Returns theMarshallingSessionassociated with this map (lazily defaults toMarshallingContext.DEFAULT_SESSION).- Returns:
- The
MarshallingSessionfor this map.
-
newMarshalledMap
Factory hook used bycast(Class)/cast(ClassMeta)when the target map type cannot be instantiated directly (e.g. when the caller asks for theMapinterface).Subclasses should override to return an instance of the matching
XMapvariant so that callers chaining off ofcast(Map. still see their flavored map type.class )- Parameters:
bs- The marshalling session to associate with the new map.- Returns:
- A new map instance.
-