public class OMap extends ObjectMap
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.
This class is not thread safe.
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
Modifier and Type | Field and Description |
---|---|
static OMap |
EMPTY_MAP
An empty read-only OMap.
|
Constructor and Description |
---|
OMap()
Construct an empty map.
|
OMap(BeanSession session)
Construct an empty map with the specified bean context.
|
OMap(CharSequence json)
Construct a map initialized with the specified JSON.
|
OMap(CharSequence in,
Parser p)
Construct a map initialized with the specified string.
|
OMap(Map<?,?> in)
Construct a map initialized with the specified map.
|
OMap(Object... keyValuePairs)
Construct a map initialized with the specified key/value pairs.
|
OMap(Reader json)
Construct a map initialized with the specified reader containing JSON.
|
OMap(Reader in,
Parser p)
Construct a map initialized with the specified string.
|
Modifier and Type | Method and Description |
---|---|
OMap |
a(String key,
Object value)
Add.
|
OMap |
aa(Map<String,Object> m)
Add all.
|
OMap |
aif(boolean overwrite,
boolean skipNullValue,
boolean skipEmptyValue,
String key,
Object value)
Add if.
|
OMap |
aif(boolean flag,
String key,
Object value)
Add if.
|
OMap |
aif(Predicate<Object> p,
String key,
Object val)
Add if predicate matches.
|
OMap |
aife(String key,
Object val)
Add if empty.
|
OMap |
aifn(String key,
Object val)
Add if null.
|
OMap |
aifne(String key,
Object val)
Add if not empty.
|
OMap |
append(String key,
Object value)
Add.
|
OMap |
appendAll(Map<String,Object> m)
Add all.
|
OMap |
appendIf(boolean overwrite,
boolean skipNullValue,
boolean skipEmptyValue,
String key,
Object value)
Add if.
|
OMap |
appendIf(boolean flag,
String key,
Object value)
Add if.
|
OMap |
appendIf(Predicate<Object> p,
String key,
Object val)
Add if predicate matches.
|
OMap |
appendIfEmpty(String key,
Object val)
Add if empty.
|
OMap |
appendIfNotEmpty(String key,
Object val)
Add if not empty.
|
OMap |
appendIfNull(String key,
Object val)
Add if null.
|
OMap |
appendSkipEmpty(String key,
Object value)
Add skip empty.
|
OMap |
appendSkipFalse(String key,
boolean value)
Add skip false.
|
OMap |
appendSkipMinusOne(String key,
Number value)
Add skip minus one.
|
OMap |
appendSkipNull(String key,
Object value)
Add skip null.
|
OMap |
ase(String key,
Object... values)
Add skip empty.
|
OMap |
asf(String key,
boolean value)
Add skip false.
|
OMap |
asmo(String key,
Number... values)
Add skip minus one.
|
OMap |
asn(String key,
Object value)
Add skip null.
|
String |
asString()
Serialize this object to Simplified JSON.
|
String |
asString(WriterSerializer serializer)
Serialize this object into a string using the specified serializer.
|
<T> T |
cast(Class<T> type)
Converts this map into an object of the specified type.
|
<T> T |
cast(ClassMeta<T> cm)
Same as
cast(Class) , except allows you to specify a ClassMeta parameter. |
boolean |
containsKey(Object key) |
boolean |
containsKeyNotEmpty(String key)
Returns
|
boolean |
containsOuterKey(Object key)
Returns
|
Object |
deleteAt(String path)
Similar to
remove(Object) , but the key is a slash-delimited path used to traverse entries
in this POJO. |
Set<Map.Entry<String,Object>> |
entrySet() |
OMap |
exclude(String... keys)
Returns a copy of this
|
<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.
|
Object |
find(String... keys)
Returns the value for the first key in the list that has an entry in this map.
|
Boolean |
findBoolean(String... keys)
Returns the first entry that exists converted to a
Boolean . |
Integer |
findInt(String... keys)
Returns the first entry that exists converted to an
Integer . |
String |
findKeyIgnoreCase(String key)
Searches for the specified key in this map ignoring case.
|
OList |
findList(String... keys)
Returns the first entry that exists converted to a
OList . |
Long |
findLong(String... keys)
Returns the first entry that exists converted to a
Long . |
OMap |
findMap(String... keys)
Returns the first entry that exists converted to a
OMap . |
String |
findString(String... keys)
Returns the first entry that exists converted to a
String . |
Object |
get(Object key) |
<T> T |
get(String key,
Class<T> type)
Same as
get() , but casts or converts the value to the specified class type. |
<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. |
<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. |
<T> T |
getAt(String path,
Type type,
Type... args)
Same as
getAt(String,Class) , but allows for conversion to complex maps and collections. |
BeanSession |
getBeanSession()
Returns the
BeanSession currently associated with this map. |
Boolean |
getBoolean(String key)
Returns the specified entry value converted to a
Boolean . |
Boolean |
getBoolean(String key,
Boolean defVal)
Returns the specified entry value converted to a
Boolean . |
ClassMeta<?> |
getClassMeta(String key)
Returns the class type of the object at the specified index.
|
String |
getFirstKey()
Returns the first key in the map.
|
Integer |
getInt(String key)
Returns the specified entry value converted to an
Integer . |
Integer |
getInt(String key,
Integer defVal)
Returns the specified entry value converted to an
Integer . |
OList |
getList(String key)
Returns the specified entry value converted to a
OList . |
OList |
getList(String key,
boolean createIfNotExists)
Same as
getList(String) but creates a new empty OList if it doesn't already exist. |
OList |
getList(String key,
OList defVal)
Returns the specified entry value converted to a
OList . |
Long |
getLong(String key)
Returns the specified entry value converted to a
Long . |
Long |
getLong(String key,
Long defVal)
Returns the specified entry value converted to a
Long . |
OMap |
getMap(String key)
Returns the specified entry value converted to a
Map . |
OMap |
getMap(String key,
boolean createIfNotExists)
Same as
getMap(String) but creates a new empty OMap if it doesn't already exist. |
OMap |
getMap(String key,
OMap defVal)
Returns the specified entry value converted to a
OMap . |
String |
getString(String key)
Returns the specified entry value converted to a
String . |
String |
getString(String key,
String defVal)
Returns the specified entry value converted to a
String . |
String[] |
getStringArray(String key)
Returns the specified entry value converted to a
String . |
String[] |
getStringArray(String key,
String[] def)
Same as
getStringArray(String) but returns a default value if the value cannot be found. |
<T> T |
getSwapped(String key,
PojoSwap<T,?> pojoSwap)
Same as
get() , but converts the raw value to the specified class type using the specified
POJO swap. |
Object |
getWithDefault(String key,
Object def)
Same as
get() , but returns the default value if the key could not be found. |
<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. |
<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. |
OMap |
include(String... keys)
Returns a copy of this
|
OMap |
inner(Map<String,Object> inner)
Set an inner map in this map to allow for chained get calls.
|
boolean |
isUnmodifiable()
Returns
|
OMap |
keepAll(String... keys)
The opposite of
removeAll(String...) . |
Set<String> |
keySet() |
OMap |
modifiable()
Returns a modifiable copy of this map if it's unmodifiable.
|
static OMap |
of()
Construct an empty map.
|
static OMap |
of(Object... keyValuePairs)
Construct a map initialized with the specified key/value pairs.
|
static OMap |
ofAll(Map<?,?> in)
Construct a map initialized with the specified map.
|
static OMap |
ofJson(CharSequence json)
Construct a map initialized with the specified JSON string.
|
static OMap |
ofJson(Reader json)
Construct a map initialized with the specified reader containing JSON.
|
static OMap |
ofText(CharSequence in,
Parser p)
Construct a map initialized with the specified string.
|
static OMap |
ofText(Reader in,
Parser p)
Construct a map initialized with the specified string.
|
Object |
postAt(String path,
Object o)
Similar to
putAt(String,Object) , but used to append to collections and arrays. |
Object |
putAt(String path,
Object o)
Same as
|
void |
putJson(String key,
String json)
Convenience method for inserting JSON directly into an attribute on this object.
|
void |
removeAll(Collection<String> keys)
Convenience method for removing several keys at once.
|
void |
removeAll(String... keys)
Convenience method for removing several keys at once.
|
Boolean |
removeBoolean(String key)
Equivalent to calling
removeWithDefault(key, . |
Boolean |
removeBoolean(String key,
Boolean def)
Equivalent to calling
removeWithDefault(key,def,Boolean. . |
Integer |
removeInt(String key)
Equivalent to calling
removeWithDefault(key, . |
Integer |
removeInt(String key,
Integer def)
Equivalent to calling
removeWithDefault(key,def,Integer. . |
String |
removeString(String key)
Equivalent to calling
removeWithDefault(key, . |
String |
removeString(String key,
String def)
Equivalent to calling
removeWithDefault(key,def,String. . |
<T> T |
removeWithDefault(String key,
T defVal,
Class<T> type)
Equivalent to calling
|
OMap |
session(BeanSession session)
Override the default bean session used for converting POJOs.
|
String |
toString()
Serialize this object into a JSON string using the
JsonSerializer.DEFAULT serializer. |
OMap |
unmodifiable()
Returns an unmodifiable copy of this map if it's modifiable.
|
OMap |
writeTo(Writer w)
Convenience method for serializing this map to the specified
JsonSerializer.DEFAULT serializer. |
findObjectList, findObjectMap, getList, getList, getMap, getMap, getObjectList, getObjectList, getObjectList, getObjectMap, getObjectMap, getObjectMap, parse, putIfEmpty, putIfNotExists, putIfNull, serializeTo, setBeanSession, setInner, toString
clear, containsValue, forEach, getOrDefault, removeEldestEntry, replaceAll, values
clone, compute, computeIfAbsent, computeIfPresent, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, size
equals, hashCode
public OMap()
public OMap(BeanSession session)
session
- The bean session to use for creating beans.public OMap(Map<?,?> in)
in
- The map to copy.
Object.toString()
.public OMap(CharSequence json) throws ParseException
json
- The JSON text to parse.
ParseException
- Malformed input encountered.public OMap(CharSequence in, Parser p) throws ParseException
in
- The input being parsed.
p
- The parser to use to parse the input.
JsonParser
.ParseException
- Malformed input encountered.public OMap(Reader json) throws ParseException
json
- The reader containing JSON text to parse.
ParseException
- Malformed input encountered.public OMap(Reader in, Parser p) throws ParseException
in
- The reader containing the input being parsed.
p
- The parser to use to parse the input.
JsonParser
.ParseException
- Malformed input encountered.public static OMap ofAll(Map<?,?> in)
in
- The map to copy.
Object.toString()
.public static OMap ofJson(CharSequence json) throws ParseException
json
- The JSON text to parse.
ParseException
- Malformed input encountered.public static OMap ofText(CharSequence in, Parser p) throws ParseException
in
- The input being parsed.
p
- The parser to use to parse the input.
JsonParser
.ParseException
- Malformed input encountered.public static OMap ofJson(Reader json) throws ParseException
json
- The reader containing JSON text to parse.
ParseException
- Malformed input encountered.public static OMap ofText(Reader in, Parser p) throws ParseException
in
- The reader containing the input being parsed.
p
- The parser to use to parse the input.
JsonParser
.ParseException
- Malformed input encountered.public static OMap of(Object... keyValuePairs)
OMap m =
keyValuePairs
- A list of key/value pairs to add to this map.public OMap inner(Map<String,Object> inner)
If get(Object)
returns get(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.
OMap m1 = OMap.
inner
- The inner map.
Can be public OMap session(BeanSession session)
Default is BeanContext.DEFAULT
, which is sufficient in most cases.
Useful if you're serializing/parsing beans with transforms defined.
session
- The new bean session.public OMap a(String key, Object value)
Adds an entry to this map.
key
- The key.value
- The value.public OMap append(String key, Object value)
Same as a(String, Object)
public OMap aif(boolean overwrite, boolean skipNullValue, boolean skipEmptyValue, String key, Object value)
Conditionally adds an entry to this map.
overwrite
- Overwrite the previous value if there was one.skipNullValue
- Skip adding the value if the value is skipEmptyValue
- Skip adding the value if the value is an empty string.key
- The key.value
- The value.public OMap appendIf(boolean overwrite, boolean skipNullValue, boolean skipEmptyValue, String key, Object value)
appendIf
in class ObjectMap
overwrite
- Overwrite the previous value if there was one.skipNullValue
- Skip adding the value if the value is skipEmptyValue
- Skip adding the value if the value is an empty string.key
- The key.value
- The value.public OMap aif(boolean flag, String key, Object value)
Conditionally adds an entry to this map.
flag
- The boolean value that must be key
- The key.value
- The value.public OMap appendIf(boolean flag, String key, Object value)
Same as aif(boolean,String,Object)
.
public OMap ase(String key, Object... values)
A no-op if the value is
key
- The key.values
- The values.public OMap appendSkipEmpty(String key, Object value)
Same as ase(String, Object...)
.
appendSkipEmpty
in class ObjectMap
key
- The key.value
- The value.public OMap asf(String key, boolean value)
A no-op if the value is
key
- The key.value
- The value.public OMap appendSkipFalse(String key, boolean value)
Same as asf(String, boolean)
.
appendSkipFalse
in class ObjectMap
key
- The key.value
- The value.public OMap asmo(String key, Number... values)
A no-op if the value is
key
- The key.values
- The values.public OMap appendSkipMinusOne(String key, Number value)
Same as asmo(String, Number...)
.
appendSkipMinusOne
in class ObjectMap
key
- The key.value
- The value.public OMap asn(String key, Object value)
key
- The key.value
- The value.public OMap appendSkipNull(String key, Object value)
Same as asn(String, Object)
.
appendSkipNull
in class ObjectMap
key
- The key.value
- The value.public OMap aa(Map<String,Object> m)
Equivalent to calling putAll(m)
, but returns this map so that the method can be chained.
m
- The map whose contents should be added to this map.public OMap aifn(String key, Object val)
Sets a value in this map if the entry does not exist or the value is
key
- The map key.val
- The value to set if the current value does not exist or is public OMap appendIfNull(String key, Object val)
Same as aifn(String, Object)
.
key
- The map key.val
- The value to set if the current value does not exist or is public OMap aife(String key, Object val)
Sets a value in this map if the entry does not exist or the value is
key
- The map key.val
- The value to set if the current value does not exist or is public OMap appendIfEmpty(String key, Object val)
Same as aife(String, Object)
.
key
- The map key.val
- The value to set if the current value does not exist or is public OMap aifne(String key, Object val)
Adds a mapping if the specified key doesn't exist.
key
- The map key.val
- The value to set if the current value does not exist or is public OMap appendIfNotEmpty(String key, Object val)
Same as aifne(String, Object)
.
key
- The map key.val
- The value to set if the current value does not exist or is public OMap aif(Predicate<Object> p, String key, Object val)
p
- The predicate to match against.key
- The map key.val
- The value to add if the predicate matches.public OMap appendIf(Predicate<Object> p, String key, Object val)
Same as aif(Predicate, String, Object)
.
p
- The predicate to match against.key
- The map key.val
- The value to add if the predicate matches.public <T> T get(String key, Class<T> type)
get()
, but casts or converts the value to the specified class type.
This is the preferred get method for simple types.
OMap m = OMap.
See BeanSession.convertToType(Object, ClassMeta)
for the list of valid data conversions.
public <T> T get(String key, Type type, Type... args)
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).
OMap m = OMap.
The array can be arbitrarily long to indicate arbitrarily complex data structures.
See BeanSession.convertToType(Object, ClassMeta)
for the list of valid data conversions.
get(String, Class)
method instead if you don't need a parameterized map/collection.
public Object getWithDefault(String key, Object def)
get()
, but returns the default value if the key could not be found.getWithDefault
in class ObjectMap
key
- The key.def
- The default value if the entry doesn't exist.public <T> T getWithDefault(String key, T def, Class<T> type)
get(String,Class)
but returns a default value if the value does not exist.getWithDefault
in class ObjectMap
T
- The class type returned.key
- The key.def
- The default value. Can be type
- The class type returned.public <T> T getWithDefault(String key, T def, Type type, Type... args)
get(String,Type,Type...)
but returns a default value if the value does not exist.getWithDefault
in class ObjectMap
T
- The class type returned.key
- The key.def
- The default value. Can be type
- The class type returned.args
- The class type parameters.public String findKeyIgnoreCase(String key)
findKeyIgnoreCase
in class ObjectMap
key
- The key to search for.
For performance reasons, it's preferable that the key be all lowercase.public <T> T getSwapped(String key, PojoSwap<T,?> pojoSwap) throws ParseException
get()
, but converts the raw value to the specified class type using the specified
POJO swap.getSwapped
in class ObjectMap
T
- The transformed class type.key
- The key.pojoSwap
- The swap class used to convert the raw type to a transformed type.ParseException
- Malformed input encountered.public Object find(String... keys)
public <T> T find(Class<T> type, String... keys)
Casts or converts the value to the specified class type.
See BeanSession.convertToType(Object, ClassMeta)
for the list of valid data conversions.
public String getString(String key)
String
.
Shortcut for get(key, String.
.
public String[] getStringArray(String key)
String
.
Shortcut for get(key, String[].
.
getStringArray
in class ObjectMap
key
- The key.public String[] getStringArray(String key, String[] def)
getStringArray(String)
but returns a default value if the value cannot be found.getStringArray
in class ObjectMap
key
- The map key.def
- The default value if value is not found.public String getString(String key, String defVal)
String
.
Shortcut for getWithDefault(key, defVal, String.
.
public Integer getInt(String key)
Integer
.
Shortcut for get(key, Integer.
.
getInt
in class ObjectMap
key
- The key.InvalidDataConversionException
- If value cannot be converted.public Integer getInt(String key, Integer defVal)
Integer
.
Shortcut for getWithDefault(key, defVal, Integer.
.
getInt
in class ObjectMap
key
- The key.defVal
- The default value if the map doesn't contain the specified mapping.InvalidDataConversionException
- If value cannot be converted.public Long getLong(String key)
Long
.
Shortcut for get(key, Long.
.
getLong
in class ObjectMap
key
- The key.InvalidDataConversionException
- If value cannot be converted.public Long getLong(String key, Long defVal)
Long
.
Shortcut for getWithDefault(key, defVal, Long.
.
getLong
in class ObjectMap
key
- The key.defVal
- The default value if the map doesn't contain the specified mapping.InvalidDataConversionException
- If value cannot be converted.public Boolean getBoolean(String key)
Boolean
.
Shortcut for get(key, Boolean.
.
getBoolean
in class ObjectMap
key
- The key.InvalidDataConversionException
- If value cannot be converted.public Boolean getBoolean(String key, Boolean defVal)
Boolean
.
Shortcut for getWithDefault(key, defVal, Boolean.
.
getBoolean
in class ObjectMap
key
- The key.defVal
- The default value if the map doesn't contain the specified mapping.InvalidDataConversionException
- If value cannot be converted.public OMap getMap(String key)
Map
.
Shortcut for get(key, OMap.
.
getMap
in class ObjectMap
key
- The key.InvalidDataConversionException
- If value cannot be converted.public OMap getMap(String key, OMap defVal)
OMap
.
Shortcut for getWithDefault(key, defVal, OMap.
.
key
- The key.defVal
- The default value if the map doesn't contain the specified mapping.InvalidDataConversionException
- If value cannot be converted.public OMap getMap(String key, boolean createIfNotExists)
getMap(String)
but creates a new empty OMap
if it doesn't already exist.key
- The key.createIfNotExists
- If mapping doesn't already exist, create one with an empty OMap
.InvalidDataConversionException
- If value cannot be converted.public OList getList(String key)
OList
.
Shortcut for get(key, OList.
.
getList
in class ObjectMap
key
- The key.InvalidDataConversionException
- If value cannot be converted.public OList getList(String key, OList defVal)
OList
.
Shortcut for getWithDefault(key, defVal, OList.
.
key
- The key.defVal
- The default value if the map doesn't contain the specified mapping.InvalidDataConversionException
- If value cannot be converted.public OList getList(String key, boolean createIfNotExists)
getList(String)
but creates a new empty OList
if it doesn't already exist.key
- The key.createIfNotExists
- If mapping doesn't already exist, create one with an empty OList
.InvalidDataConversionException
- If value cannot be converted.public String findString(String... keys)
String
.
Shortcut for find(String.
.
findString
in class ObjectMap
keys
- The list of keys to look for.public Integer findInt(String... keys)
Integer
.
Shortcut for find(Integer.
.
findInt
in class ObjectMap
keys
- The list of keys to look for.InvalidDataConversionException
- If value cannot be converted.public Long findLong(String... keys)
Long
.
Shortcut for find(Long.
.
findLong
in class ObjectMap
keys
- The list of keys to look for.InvalidDataConversionException
- If value cannot be converted.public Boolean findBoolean(String... keys)
Boolean
.
Shortcut for find(Boolean.
.
findBoolean
in class ObjectMap
keys
- The list of keys to look for.InvalidDataConversionException
- If value cannot be converted.public OMap findMap(String... keys)
OMap
.
Shortcut for find(OMap.
.
findMap
in class ObjectMap
keys
- The list of keys to look for.InvalidDataConversionException
- If value cannot be converted.public OList findList(String... keys)
OList
.
Shortcut for find(OList.
.
findList
in class ObjectMap
keys
- The list of keys to look for.InvalidDataConversionException
- If value cannot be converted.public String getFirstKey()
getFirstKey
in class ObjectMap
public ClassMeta<?> getClassMeta(String key)
getClassMeta
in class ObjectMap
key
- The key into this map.public <T> T removeWithDefault(String key, T defVal, Class<T> type)
removeWithDefault
in class ObjectMap
T
- The class type.key
- The key.defVal
- The default value if the map doesn't contain the specified mapping.type
- The class type.InvalidDataConversionException
- If value cannot be converted.public String removeString(String key)
removeWithDefault(key,null ,String.class )
.removeString
in class ObjectMap
key
- The key.InvalidDataConversionException
- If value cannot be converted.public String removeString(String key, String def)
removeWithDefault(key,def,String.class )
.removeString
in class ObjectMap
key
- The key.def
- The default value if the map doesn't contain the specified mapping.InvalidDataConversionException
- If value cannot be converted.public Integer removeInt(String key)
removeWithDefault(key,null ,Integer.class )
.removeInt
in class ObjectMap
key
- The key.InvalidDataConversionException
- If value cannot be converted.public Integer removeInt(String key, Integer def)
removeWithDefault(key,def,Integer.class )
.removeInt
in class ObjectMap
key
- The key.def
- The default value if the map doesn't contain the specified mapping.InvalidDataConversionException
- If value cannot be converted.public Boolean removeBoolean(String key)
removeWithDefault(key,null ,Boolean.class )
.removeBoolean
in class ObjectMap
key
- The key.InvalidDataConversionException
- If value cannot be converted.public Boolean removeBoolean(String key, Boolean def)
removeWithDefault(key,def,Boolean.class )
.removeBoolean
in class ObjectMap
key
- The key.def
- The default value if the map doesn't contain the specified mapping.InvalidDataConversionException
- If value cannot be converted.public void removeAll(Collection<String> keys)
public void removeAll(String... keys)
public OMap keepAll(String... keys)
removeAll(String...)
.
Discards all keys from this map that aren't in the specified list.
public boolean containsKeyNotEmpty(String key)
Always returns CharSequence
.
containsKeyNotEmpty
in class ObjectMap
key
- The key.public boolean containsOuterKey(Object key)
containsOuterKey
in class ObjectMap
key
- The key to look up.public OMap include(String... keys)
public <T> T cast(Class<T> type)
If this map contains a
cast
in class ObjectMap
T
- The class type to convert this map object to.type
- The class type to convert this map object to.ClassCastException
- If the public <T> T cast(ClassMeta<T> cm)
cast(Class)
, except allows you to specify a ClassMeta
parameter.cast
in class ObjectMap
T
- The class type to convert this map object to.cm
- The class type to convert this map object to.ClassCastException
- If the public <T> T getAt(String path, Class<T> type)
get(String,Class)
, but the key is a slash-delimited path used to traverse
entries in this POJO.
For example, the following code is equivalent:
OMap m = OMap.
This method uses the PojoRest
class to perform the lookup, so the map can contain any of the various
class types that the PojoRest
class supports (e.g. beans, collections, arrays).
public <T> T getAt(String path, Type type, Type... args)
getAt(String,Class)
, but allows for conversion to complex maps and collections.
This method uses the PojoRest
class to perform the lookup, so the map can contain any of the various
class types that the PojoRest
class supports (e.g. beans, collections, arrays).
public Object putAt(String path, Object o)
For example, the following code is equivalent:
OMap m = OMap.
This method uses the PojoRest
class to perform the lookup, so the map can contain any of the various
class types that the PojoRest
class supports (e.g. beans, collections, arrays).
public Object postAt(String path, Object o)
putAt(String,Object)
, but used to append to collections and arrays.
For example, the following code is equivalent:
OMap m = OMap.
This method uses the PojoRest
class to perform the lookup, so the map can contain any of the various
class types that the PojoRest
class supports (e.g. beans, collections, arrays).
public Object deleteAt(String path)
remove(Object)
, but the key is a slash-delimited path used to traverse entries
in this POJO.
For example, the following code is equivalent:
OMap m = OMap.
This method uses the PojoRest
class to perform the lookup, so the map can contain any of the various
class types that the PojoRest
class supports (e.g. beans, collections, arrays).
public BeanSession getBeanSession()
BeanSession
currently associated with this map.getBeanSession
in class ObjectMap
BeanSession
currently associated with this map.public void putJson(String key, String json) throws ParseException
The JSON text can be an object (i.e.
putJson
in class ObjectMap
key
- The key.json
- The JSON text that will be parsed into an Object and then inserted into this map.ParseException
- Malformed input encountered.public String asString(WriterSerializer serializer)
serializer
- The serializer to use to convert this object to a string.public String asString()
public OMap writeTo(Writer w) throws IOException, SerializeException
JsonSerializer.DEFAULT
serializer.w
- The writer to serialize this object to.IOException
- If a problem occurred trying to write to the writer.SerializeException
- If a problem occurred trying to convert the output.public boolean isUnmodifiable()
isUnmodifiable
in class ObjectMap
public OMap modifiable()
modifiable
in class ObjectMap
public OMap unmodifiable()
unmodifiable
in class ObjectMap
public boolean containsKey(Object key)
containsKey
in interface Map<String,Object>
containsKey
in class ObjectMap
Copyright © 2016–2020 The Apache Software Foundation. All rights reserved.