Class JsonMap
- All Implemented Interfaces:
- Serializable,- Cloneable,- Map<String,- Object> 
- Direct Known Subclasses:
- Args,- DelegateMap,- ManifestFile,- ResolvingJsonMap
 An extension of LinkedHashMap, so all methods available in that class are also available to this class.
 
 Note that the use of this class is optional for generating JSON. The serializers will accept any objects that implement the
 Map interface.  But this class provides some useful additional functionality when working with
 JSON models constructed from Java Collections Framework objects.  For example, a constructor is provided for
 converting a JSON object string directly into a Map.  It also contains accessor methods for to avoid common
 typecasting when accessing elements in a list.
 
Example:
   
Notes:
- This class is not thread safe.
- See Also:
- 
Nested Class SummaryNested classes/interfaces inherited from class java.util.AbstractMapAbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object, V extends Object> 
- 
Field SummaryFields
- 
Constructor SummaryConstructorsConstructorDescriptionJsonMap()Construct an empty map.Construct a map initialized with the specified reader containing JSON.Construct a map initialized with the specified string.JsonMap(CharSequence json) Construct a map initialized with the specified JSON.JsonMap(CharSequence in, Parser p) Construct a map initialized with the specified string.Construct a map initialized with the specified key/value pairs.Construct a map initialized with the specified map.JsonMap(BeanSession session) Construct an empty map with the specified bean context.
- 
Method SummaryModifier and TypeMethodDescriptionAdds an entry to this map.Appends all the entries in the specified map to this map.final <T> JsonMapappendFirst(Predicate<T> test, String key, T... values) Adds the first value that matches the specified predicate.Add if flag istrue .<T> JsonMapAdd 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> JsonMapappendIfAbsentIf(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.asJson()A synonym fortoString()Serialize this object to Simplified JSON usingJson5Serializer.DEFAULT_READABLE.asString()Serialize this object to Simplified JSON usingJson5Serializer.DEFAULT.asString(WriterSerializer serializer) Serialize this object into a string using the specified serializer.<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 JsonMapcreate()Construct an empty map.Similar toremove(Object), but the key is a slash-delimited path used to traverse entries in this POJO.entrySet()Returns a copy of thisJsonMap without the specified keys.filtered()Enables filtering based on default values.Enables filtering based on a predicate test.static JsonMapConstruct an empty map.static JsonMapfilteredMap(Object... keyValuePairs) Construct a 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 aJsonList.Returns the first entry that exists converted to aLong.Returns the first entry that exists converted to aJsonMap.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.Returns theBeanSessioncurrently associated with this map.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 aJsonList.Same asgetList(String)but creates a new emptyJsonListif it doesn't already exist.<E> List<E>Same asgetList(String, JsonList)except converts the elements to the specified types.Returns the specified entry value converted to aJsonList.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 emptyJsonMapif it doesn't already exist.<K,V> Map<K, V> Same asgetMap(String, JsonMap)except converts the keys and values to the specified types.Returns the specified entry value converted to aJsonMap.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.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.Returns a copy of thisJsonMap with only the specified keys.Set an inner map in this map to allow for chained get calls.booleanReturnstrue if this map is unmodifiable.The opposite ofremoveAll(String...).keySet()Returns a modifiable copy of this map if it's unmodifiable.static JsonMapConstruct a map initialized with the specified key/value pairs.static JsonMapConstruct a map initialized with the specified map.static JsonMapConstruct a map initialized with the specified reader containing JSON.static JsonMapofJson(CharSequence json) Construct a map initialized with the specified JSON string.static JsonMapConstruct a map initialized with the specified string.static JsonMapofText(CharSequence in, Parser p) Construct a map initialized with the specified string.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 inserting JSON directly into an attribute on this object.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(BeanSession session) Override the default bean session used for converting POJOs.setBeanSession(BeanSession value) Sets theBeanSessioncurrently associated with this map.toString()Returns an unmodifiable copy of this map if it's modifiable.Convenience method for serializing this map to the specifiedWriter using theJsonSerializer.DEFAULTserializer.Methods inherited from class java.util.LinkedHashMapclear, containsValue, forEach, getOrDefault, removeEldestEntry, replaceAll, valuesMethods inherited from class java.util.HashMapclone, compute, computeIfAbsent, computeIfPresent, isEmpty, merge, putAll, putIfAbsent, remove, remove, replace, replace, sizeMethods inherited from class java.util.AbstractMapequals, hashCodeMethods inherited from class java.lang.Objectfinalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Mapcompute, computeIfAbsent, computeIfPresent, equals, hashCode, isEmpty, merge, putAll, putIfAbsent, remove, remove, replace, replace, size
- 
Field Details- 
EMPTY_MAPAn empty read-only JsonMap.
 
- 
- 
Constructor Details- 
JsonMappublic JsonMap()Construct an empty map.
- 
JsonMapConstruct an empty map with the specified bean context.- Parameters:
- session- The bean session to use for creating beans.
 
- 
JsonMapConstruct a map initialized with the specified map.- Parameters:
- in- The map to copy.
 Can be- null .
 Keys will be converted to strings using- Object.toString().
 
- 
JsonMapConstruct a map initialized with the specified JSON.- Parameters:
- json- The JSON text to parse.
 Can be normal or simplified JSON.
- Throws:
- ParseException- Malformed input encountered.
 
- 
JsonMapConstruct a map initialized with the specified string.- Parameters:
- in- The input being parsed.
 Can be- null .
- p- The parser to use to parse the input.
 If- null , uses- JsonParser.
- Throws:
- ParseException- Malformed input encountered.
 
- 
JsonMapConstruct a map initialized with the specified reader containing JSON.- Parameters:
- json- The reader containing JSON text to parse.
 Can contain normal or simplified JSON.
- Throws:
- ParseException- Malformed input encountered.
 
- 
JsonMapConstruct a map initialized with the specified string.- Parameters:
- in- The reader containing the input being parsed.
 Can contain normal or simplified JSON.
- p- The parser to use to parse the input.
 If- null , uses- JsonParser.
- Throws:
- ParseException- Malformed input encountered.
 
- 
JsonMapConstruct a map initialized with the specified key/value pairs.Examples:JsonMap map =new JsonMap("key1" ,"val1" ,"key2" ,"val2" );- Parameters:
- keyValuePairs- A list of key/value pairs to add to this map.
 
 
- 
- 
Method Details- 
createConstruct an empty map.- Returns:
- An empty map.
 
- 
filteredMapConstruct an empty map.- Returns:
- An empty map.
 
- 
ofConstruct a map initialized with the specified map.- Parameters:
- values- The map to copy.
 Can be- null .
 Keys will be converted to strings using- Object.toString().
- Returns:
- A new map or null if the map wasnull .
 
- 
ofJsonConstruct a map initialized with the specified JSON string.- Parameters:
- json- The JSON text to parse.
 Can be normal or simplified JSON.
- Returns:
- A new map or null if the string was null.
- Throws:
- ParseException- Malformed input encountered.
 
- 
ofTextConstruct a map initialized with the specified string.- Parameters:
- in- The input being parsed.
 Can be- null .
- p- The parser to use to parse the input.
 If- null , uses- JsonParser.
- Returns:
- A new map or null if the input wasnull .
- Throws:
- ParseException- Malformed input encountered.
 
- 
ofJsonConstruct a map initialized with the specified reader containing JSON.- Parameters:
- json- The reader containing JSON text to parse.
 Can contain normal or simplified JSON.
- Returns:
- A new map or null if the input wasnull .
- Throws:
- ParseException- Malformed input encountered.
 
- 
ofTextConstruct a map initialized with the specified string.- Parameters:
- in- The reader containing the input being parsed.
 Can contain normal or simplified JSON.
- p- The parser to use to parse the input.
 If- null , uses- JsonParser.
- Returns:
- A new map or null if the input wasnull .
- Throws:
- ParseException- Malformed input encountered.
 
- 
ofConstruct a map initialized with the specified key/value pairs.Examples:JsonMap map =new JsonMap("key1" ,"val1" ,"key2" ,"val2" );- Parameters:
- keyValuePairs- A list of key/value pairs to add to this map.
- Returns:
- A new map, never null .
 
- 
filteredMapConstruct a map initialized with the specified key/value pairs.Same as of(Object...)but callsfiltered()on the created map.Examples:JsonMap map =new JsonMap("key1" ,"val1" ,"key2" ,"val2" );- Parameters:
- keyValuePairs- A list of key/value pairs to add to this map.
- Returns:
- A new map, never null .
 
- 
innerSet 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.In addition to providing the ability to chain maps, this method also provides the ability to wrap an existing map inside another map so that you can add entries to the outer map without affecting the values on the inner map. JsonMap map1 = JsonMap.ofJson ("{foo:1}" ); JsonMapmap2 = JsonMap.of ().setInner(map1 );map2 .put("foo" , 2);// Overwrite the entry int foo1 =map1 .getInt("foo" );// foo1 == 1 int foo2 =map2 .getInt("foo" );// foo2 == 2 - Parameters:
- inner- The inner map. Can be- null to remove the inner map from an existing map.
- Returns:
- This object.
 
- 
sessionOverride the default bean session used for converting POJOs.Default is BeanContext.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.
 
- 
appendAdds an entry to this map.- Parameters:
- key- The key.
- value- The value.
- Returns:
- This object.
 
- 
appendAppends all the entries in the specified map to this map.- Parameters:
- values- The map to copy. Can be- null .
- Returns:
- This object.
 
- 
appendIfAdd if flag istrue .- Parameters:
- flag- The flag to check.
- key- The key.
- value- The value.
- Returns:
- This object.
 
- 
appendIfAdd 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.
 
- 
appendFirstAdds 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.
 
- 
appendIfAbsentAdds 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 is- null .
- Returns:
- This object.
 
- 
appendIfAbsentIfAdds 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 is- null .
- Returns:
- This object.
 
- 
filteredEnables 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.
 
- 
filteredEnables 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.
 
- 
getSame asget(), but casts or converts the value to the specified class type.This is the preferred get method for simple types. Examples:JsonMap map = JsonMap.ofJson ("..." );// Value converted to a string. Stringstring =map .get("key1" , String.class );// Value converted to a bean. MyBeanbean =map .get("key2" , MyBean.class );// Value converted to a bean array. MyBean[]beanArray =map .get("key3" , MyBean[].class );// Value converted to a linked-list of objects. Listlist =map .get("key4" , LinkedList.class );// Value converted to a map of object keys/values. Mapmap2 =map .get("key5" , TreeMap.class );See BeanSession.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.
 
- 
getSame 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). Examples:JsonMap map = JsonMap.ofJson ("..." );// Value converted to a linked-list of strings. List<String>list1 =map .get("key1" , LinkedList.class , String.class );// Value converted to a linked-list of beans. List<MyBean>list2 =map .get("key2" , LinkedList.class , MyBean.class );// Value converted to a linked-list of linked-lists of strings. List<List<String>>list3 =map .get("key3" , LinkedList.class , LinkedList.class , String.class );// Value converted to a map of string keys/values. Map<String,String>map1 =map .get("key4" , TreeMap.class , String.class , String.class );// Value converted to a map containing string keys and values of lists containing beans. Map<String,List<MyBean>>map2 =map .get("key5" , TreeMap.class , String.class , List.class , MyBean.class );Collection classes are assumed to be followed by zero or one objects indicating the element type.Map classes are assumed to be followed by zero or two meta objects indicating the key and value types.The array can be arbitrarily long to indicate arbitrarily complex data structures. See BeanSession.convertToType(Object, ClassMeta)for the list of valid data conversions.Notes:- 
      Use the get(String, Class)method instead if you don't need a parameterized map/collection.
 - 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.
 
- 
      Use the 
- 
getWithDefaultSame 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.
 
- 
getWithDefaultSame 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 be- null .
- type- The class type returned.
- Returns:
- The value, or null if the entry doesn't exist.
 
- 
getWithDefaultSame 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 be- null .
- type- The class type returned.
- args- The class type parameters.
- Returns:
- The value, or null if the entry doesn't exist.
 
- 
findKeyIgnoreCaseSearches 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.
 
- 
getSwappedSame 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.
 
- 
findReturns 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.
 
- 
findReturns 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 BeanSession.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.
 
- 
getStringReturns the specified entry value converted to aString.Shortcut for get(key, String..class )- Parameters:
- key- The key.
- Returns:
- The converted value, or null if the map contains no mapping for this key.
 
- 
getStringArrayReturns the specified entry value converted to aString.Shortcut for get(key, String[]..class )- Parameters:
- key- The key.
- Returns:
- The converted value, or null if the map contains no mapping for this key.
 
- 
getStringArraySame 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.
 
- 
getStringReturns the specified entry value converted to aString.Shortcut for getWithDefault(key, defVal, String..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.
 
- 
getIntReturns the specified entry value converted to anInteger.Shortcut for get(key, 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.
 
- 
getIntReturns the specified entry value converted to anInteger.Shortcut for getWithDefault(key, defVal, Integer..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.
 
- 
getLongReturns the specified entry value converted to aLong.Shortcut for get(key, Long..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.
 
- 
getLongReturns the specified entry value converted to aLong.Shortcut for getWithDefault(key, defVal, Long..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.
 
- 
getBooleanReturns the specified entry value converted to aBoolean.Shortcut for get(key, 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.
 
- 
getBooleanReturns the specified entry value converted to aBoolean.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.
 
- 
getMapReturns the specified entry value converted to aMap.Shortcut for get(key, JsonMap..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.
 
- 
getMapReturns the specified entry value converted to aJsonMap.Shortcut for getWithDefault(key, defVal, JsonMap..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.
 
- 
getMapSame asgetMap(String)but creates a new emptyJsonMapif it doesn't already exist.- Parameters:
- key- The key.
- createIfNotExists- If mapping doesn't already exist, create one with an empty- JsonMap.
- Returns:
- The converted value, or an empty value if the map contains no mapping for this key.
- Throws:
- InvalidDataConversionException- If value cannot be converted.
 
- 
getMapSame asgetMap(String, JsonMap)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.
 
- 
getListReturns the specified entry value converted to aJsonList.Shortcut for get(key, JsonList..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.
 
- 
getListReturns the specified entry value converted to aJsonList.Shortcut for getWithDefault(key, defVal, JsonList..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.
 
- 
getListSame asgetList(String)but creates a new emptyJsonListif it doesn't already exist.- Parameters:
- key- The key.
- createIfNotExists- If mapping doesn't already exist, create one with an empty- JsonList.
- Returns:
- The converted value, or an empty value if the map contains no mapping for this key.
- Throws:
- InvalidDataConversionException- If value cannot be converted.
 
- 
getListSame asgetList(String, JsonList)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.
 
- 
findStringReturns the first entry that exists converted to aString.Shortcut for find(String..class , keys)- 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.
 
- 
findIntReturns the first entry that exists converted to anInteger.Shortcut for find(Integer..class , keys)- 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.
 
- 
findLongReturns the first entry that exists converted to aLong.Shortcut for find(Long..class , keys)- 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.
 
- 
findBooleanReturns the first entry that exists converted to aBoolean.Shortcut for find(Boolean..class , keys)- 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.
 
- 
findMapReturns the first entry that exists converted to aJsonMap.Shortcut for find(JsonMap..class , keys)- 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.
 
- 
findListReturns the first entry that exists converted to aJsonList.Shortcut for find(JsonList..class , keys)- 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.
 
- 
getFirstKeyReturns the first key in the map.- Returns:
- The first key in the map, or null if the map is empty.
 
- 
getClassMetaReturns 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.
 
- 
removeWithDefaultEquivalent 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.
 
- 
removeStringEquivalent 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.
 
- 
removeStringEquivalent 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.
 
- 
removeIntEquivalent 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.
 
- 
removeIntEquivalent 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.
 
- 
removeBooleanEquivalent 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.
 
- 
removeBooleanEquivalent 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.
 
- 
removeAllConvenience method for removing several keys at once.- Parameters:
- keys- The list of keys to remove.
 
- 
removeAllConvenience method for removing several keys at once.- Parameters:
- keys- The list of keys to remove.
 
- 
keepAllThe 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.
 
- 
containsKeyNotEmptyReturnstrue 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.
 
- 
containsOuterKeyReturnstrue 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.
 
- 
includeReturns a copy of thisJsonMap 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.
 
- 
excludeReturns a copy of thisJsonMap 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.
 
- 
castConverts 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 from- type 
 
- 
castSame 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 from- type 
 
- 
getAtSame asget(String,Class), but the key is a slash-delimited path used to traverse entries in this POJO.For example, the following code is equivalent: JsonMap map = JsonMap.ofJson ("..." );// Long way long _long =map .getMap("foo" ).getList("bar" ).getMap("0" ).getLong("baz" );// Using this method long _long =map .getAt("foo/bar/0/baz" ,long .class );This method uses the ObjectRestclass to perform the lookup, so the map can contain any of the various class types that theObjectRestclass supports (e.g. beans, collections, arrays).- 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.
 
- 
getAtSame asgetAt(String,Class), but allows for conversion to complex maps and collections.This method uses the ObjectRestclass to perform the lookup, so the map can contain any of the various class types that theObjectRestclass supports (e.g. beans, collections, arrays).- 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.
 
- 
putAtSame asput(String,Object) , but the key is a slash-delimited path used to traverse entries in this POJO.For example, the following code is equivalent: JsonMap map = JsonMap.ofJson ("..." );// Long way map .getMap("foo" ).getList("bar" ).getMap("0" ).put("baz" , 123);// Using this method map .putAt("foo/bar/0/baz" , 123);This method uses the ObjectRestclass to perform the lookup, so the map can contain any of the various class types that theObjectRestclass 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.
 
- 
postAtSimilar toputAt(String,Object), but used to append to collections and arrays.For example, the following code is equivalent: JsonMap map = JsonMap.ofJson ("..." );// Long way map .getMap("foo" ).getList("bar" ).append(123);// Using this method map .postAt("foo/bar" , 123);This method uses the ObjectRestclass to perform the lookup, so the map can contain any of the various class types that theObjectRestclass 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.
 
- 
deleteAtSimilar toremove(Object), but the key is a slash-delimited path used to traverse entries in this POJO.For example, the following code is equivalent: JsonMap map = JsonMap.ofJson ("..." );// Long way map .getMap("foo" ).getList("bar" ).getMap(0).remove("baz" );// Using this method map .deleteAt("foo/bar/0/baz" );This method uses the ObjectRestclass to perform the lookup, so the map can contain any of the various class types that theObjectRestclass 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.
 
- 
put
- 
getBeanSessionReturns theBeanSessioncurrently associated with this map.- Returns:
- The BeanSessioncurrently associated with this map.
 
- 
setBeanSessionSets theBeanSessioncurrently associated with this map.- Parameters:
- value- The- BeanSessioncurrently associated with this map.
- Returns:
- This object.
 
- 
putJsonConvenience method for inserting JSON directly into an attribute on this object.The JSON text can be an object (i.e. "{...}" ) or an array (i.e."[...]" ).- Parameters:
- key- The key.
- json- The JSON text that will be parsed into an Object and then inserted into this map.
- Throws:
- ParseException- Malformed input encountered.
 
- 
asStringSerialize this object into 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.
 
- 
asStringSerialize this object to Simplified JSON usingJson5Serializer.DEFAULT.- Returns:
- This object serialized as a string.
 
- 
asReadableStringSerialize this object to Simplified JSON usingJson5Serializer.DEFAULT_READABLE.- Returns:
- This object serialized as a string.
 
- 
writeToConvenience method for serializing this map to the specifiedWriter using theJsonSerializer.DEFAULTserializer.- Parameters:
- w- The writer to serialize this object to.
- Returns:
- This object.
- Throws:
- IOException- If a problem occurred trying to write to the writer.
- SerializeException- If a problem occurred trying to convert the output.
 
- 
isUnmodifiableReturnstrue if this map is unmodifiable.- Returns:
- true if this map is unmodifiable.
 
- 
modifiableReturns 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.
 
- 
unmodifiableReturns 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.
 
- 
get
- 
containsKey- Specified by:
- containsKeyin interface- Map<String,- Object> 
- Overrides:
- containsKeyin class- HashMap<String,- Object> 
 
- 
keySet
- 
entrySet
- 
asJsonA synonym fortoString()- Returns:
- This object as a JSON string.
 
- 
toString- Overrides:
- toStringin class- AbstractMap<String,- Object> 
 
 
-