Constructor and Description |
---|
JsonValueKeyAccessChecker(JsonValue delegate)
Constructs a
JsonValueKeyAccessChecker . |
Modifier and Type | Method and Description |
---|---|
JsonValue |
add(int index,
Object object)
Adds the specified value to the list.
|
JsonValue |
add(JsonPointer pointer,
Object object)
Adds the value identified by the specified pointer, relative to this
value as root.
|
JsonValue |
add(Object object)
Adds the specified value to a set or to the end of the list.
|
JsonValue |
add(String key,
Object object)
Adds the specified value.
|
JsonValue |
addPermissive(JsonPointer pointer,
Object object)
Adds the value identified by the specified pointer, relative to this
value as root.
|
void |
applyTransformers()
Applies all of the transformations to the value.
|
Boolean |
asBoolean()
Returns the JSON value as a
Boolean object. |
Charset |
asCharset()
Returns the JSON string value as a character set used for byte
encoding/decoding.
|
Double |
asDouble()
Returns the JSON value as a
Double object. |
<T extends Enum<T>> |
asEnum(Class<T> type)
Returns the JSON string value as an enum constant of the specified enum
type.
|
File |
asFile()
Returns the JSON string value as a
File object. |
Integer |
asInteger()
Returns the JSON value as an
Integer object. |
List<Object> |
asList()
Returns the JSON value as a
List object. |
<E> List<E> |
asList(Class<E> type)
Returns the JSON value as a
List containing objects of the
specified type. |
Long |
asLong()
Returns the JSON value as a
Long object. |
Map<String,Object> |
asMap()
Returns the JSON value as a
Map object. |
Number |
asNumber()
Returns the JSON value as a
Number object. |
Pattern |
asPattern()
Returns the JSON string value as a regular expression pattern.
|
JsonPointer |
asPointer()
Returns the JSON string value as a JSON pointer.
|
String |
asString()
Returns the JSON value as a
String object. |
URI |
asURI()
Returns the JSON string value as a uniform resource identifier.
|
UUID |
asUUID()
Returns the JSON string value as a universally unique identifier (UUID).
|
void |
clear()
Removes all child values from this JSON value, if it has any.
|
JsonValue |
clone()
Returns a shallow copy of this JSON value.
|
boolean |
contains(Object object)
Returns
true this JSON value contains an item with the specified
value. |
JsonValue |
copy()
Returns a deep copy of this JSON value.
|
JsonValue |
defaultTo(Object object)
Defaults the JSON value to the specified value if it is currently
null . |
boolean |
equals(Object obj) |
JsonValue |
expect(Class<?> type)
Called to enforce that the JSON value is of a particular type.
|
JsonValue |
get(int index)
Returns the specified child value.
|
JsonValue |
get(JsonPointer pointer)
Returns the specified child value with a pointer, relative to this value
as root.
|
JsonValue |
get(String key)
Returns the specified item value.
|
Object |
getObject()
Returns the raw Java object representing this JSON value.
|
JsonPointer |
getPointer()
Returns the pointer of the JSON value in its JSON structure.
|
List<JsonTransformer> |
getTransformers()
Returns the JSON value's list of transformers.
|
int |
hashCode() |
boolean |
isBoolean()
Returns
true if the JSON value is a Boolean . |
boolean |
isDefined(String key)
Returns
true if this JSON value contains the specified item. |
boolean |
isList()
Returns
true if the JSON value is a List . |
boolean |
isMap()
Returns
true if the JSON value is a Map . |
boolean |
isNull()
Returns
true if the value is null . |
boolean |
isNumber()
Returns
true if the JSON value is a Number . |
boolean |
isString()
Returns
true if the JSON value is a String . |
Iterator<JsonValue> |
iterator()
Returns an iterator over the child values that this JSON value contains.
|
Set<String> |
keys()
Returns the set of keys for this JSON value's child values.
|
JsonValue |
put(int index,
Object object)
Sets the value of the specified child list element.
|
JsonValue |
put(JsonPointer pointer,
Object object)
Sets the value identified by the specified pointer, relative to this
value as root.
|
JsonValue |
put(String key,
Object object)
Sets the value of the specified member.
|
JsonValue |
putPermissive(JsonPointer pointer,
Object object)
Sets the value identified by the specified pointer, relative to this
value as root.
|
JsonValue |
recordKeyAccesses()
Returns a subclass of JsonValue that records which keys are accessed in this
JsonValue and its children. |
void |
remove(int index)
Removes the specified child value, shifting any subsequent elements to
the left.
|
void |
remove(JsonPointer pointer)
Removes the specified child value with a pointer, relative to this value
as root.
|
void |
remove(String key)
Removes the specified child value.
|
JsonValue |
required()
Throws a
JsonValueException if the JSON value is null . |
void |
setObject(Object object)
Sets the Java object representing this JSON value.
|
int |
size()
Returns the number of values that this JSON value contains.
|
String |
toString()
Returns a string representation of the JSON value.
|
void |
verifyAllKeysAccessed()
Verifies that all keys in this
JsonValue and its children have been accessed. |
array, asCollection, asCollection, asList, asMap, asMapOfList, asSet, asSet, asSet, asURL, field, fieldIfNotNull, isCollection, isNotNull, isSet, json, object, set
public JsonValueKeyAccessChecker(JsonValue delegate)
JsonValueKeyAccessChecker
.delegate
- The delegate to checkpublic JsonValue recordKeyAccesses()
JsonValue
and its children.
Call #verifyAllKeysAccessed() to verify that all keys were accessed. The returned JsonValue provides an
immutable view on the monitored underlying JsonValue.recordKeyAccesses
in class JsonValue
JsonValue.verifyAllKeysAccessed()
public void verifyAllKeysAccessed()
JsonValue
and its children have been accessed. #recordKeyAccesses() must
have been called before, otherwise this method will do nothing.verifyAllKeysAccessed
in class JsonValue
JsonValue.recordKeyAccesses()
public JsonValue add(int index, Object object)
public JsonValue add(JsonPointer pointer, Object object)
JsonValueException
will be thrown.
NOTE: values may be added to a list using the reserved JSON pointer token "-". For example, the pointer "/a/b/-" will add a new element to the list referenced by "/a/b".
public JsonValue add(Object object)
add(size(), object);for lists, and
asSet().add(object);for sets.
public JsonValue add(String key, Object object)
If adding to a list value, the specified key must be parseable as an unsigned base-10 integer and be less than or equal to the list size. Adding a value to a list shifts any existing elements at or above the specified index to the right by one.
public JsonValue addPermissive(JsonPointer pointer, Object object)
NOTE: values may be added to a list using the reserved JSON pointer token "-". For example, the pointer "/a/b/-" will add a new element to the list referenced by "/a/b".
addPermissive
in class JsonValue
pointer
- identifies the child value to add.object
- the Java object value to add.public void applyTransformers()
This method has an absurdly high upper-limit of Integer.MAX_VALUE
iterations, beyond which a JsonException
will be thrown.
applyTransformers
in class JsonValue
public Charset asCharset()
null
, this method returns
null
.public Double asDouble()
Double
object. This may involve
rounding. If the JSON value is null
, this method returns
null
.public <T extends Enum<T>> T asEnum(Class<T> type)
null
, this method returns
null
.public File asFile()
File
object. If the JSON value
is null
, this method returns null
.public Integer asInteger()
Integer
object. This may involve
rounding or truncation. If the JSON value is null
, this method
returns null
.public <E> List<E> asList(Class<E> type)
List
containing objects of the
specified type. If the value is null
, this method returns
null
. If any of the elements of the list are not null
and
not of the specified type, JsonValueException
is thrown.public Long asLong()
Long
object. This may involve
rounding or truncation. If the JSON value is null
, this method
returns null
.public Map<String,Object> asMap()
Map
object. If the JSON value is
null
, this method returns null
.public Number asNumber()
Number
object. If the JSON value is
null
, this method returns null
.public Pattern asPattern()
null
, this method returns null
.public JsonPointer asPointer()
null
, this method returns null
.public String asString()
String
object. If the JSON value is
null
, this method returns null
.public URI asURI()
null
, this method returns null
.public UUID asUUID()
null
, this method returns null
.public void clear()
public JsonValue clone()
Map
, a Set
, or a List
object, the returned JSON
value will contain a shallow copy of the original contained object.
The new value's members can be modified without affecting the original
value. Modifying the member's members will almost certainly affect the
original value. To avoid this, use the JsonValue.copy()
method to return a
deep copy of the JSON value.
This method does not traverse the value's members, nor will it apply any transformations.
public boolean contains(Object object)
true
this JSON value contains an item with the specified
value.public JsonValue copy()
This method applies all transformations while traversing the values's members and their members, and so on. Consequently, the returned copy does not include the transformers from this value.
Note: This method is recursive, and currently has no ability to detect or
correct for structures containing cyclic references. Processing such a
structure will result in a StackOverflowError
being thrown.
public JsonValue defaultTo(Object object)
null
.public JsonValue expect(Class<?> type)
null
is allowed.public JsonValue get(int index)
List
or if no such child exists, then a JSON value containing a
null
is returned.public JsonValue get(JsonPointer pointer)
null
is returned.public JsonValue get(String key)
null
is returned.public JsonPointer getPointer()
getPointer
in class JsonValue
public List<JsonTransformer> getTransformers()
JsonValue.applyTransformers()
method to apply them to the current value.getTransformers
in class JsonValue
public boolean isDefined(String key)
true
if this JSON value contains the specified item.public boolean isNull()
true
if the value is null
.public Iterator<JsonValue> iterator()
Map
or a Set
, then the order of the
resulting child values is undefined. Calling the Iterator.remove()
method of the returned iterator will throw a UnsupportedOperationException
.
Note: calls to the next()
method may throw the runtime
JsonException
if any transformers fail to execute.
public Set<String> keys()
Map
, then the order of the resulting keys is the same as the
underlying Map implementation. If there are no child values, this method
returns an empty set.public JsonValue put(int index, Object object)
public JsonValue put(JsonPointer pointer, Object object)
JsonValueException
will be thrown.
NOTE: values may be added to a list using the reserved JSON pointer token "-". For example, the pointer "/a/b/-" will add a new element to the list referenced by "/a/b".
public JsonValue put(String key, Object object)
If setting a list element, the specified key must be parseable as an unsigned base-10 integer and be less than or equal to the size of the list.
public JsonValue putPermissive(JsonPointer pointer, Object object)
NOTE: values may be added to a list using the reserved JSON pointer token "-". For example, the pointer "/a/b/-" will add a new element to the list referenced by "/a/b".
putPermissive
in class JsonValue
pointer
- identifies the child value to set.object
- the Java object value to set.public void remove(int index)
List
, calling this method
has no effect.public void remove(JsonPointer pointer)
public void remove(String key)
public void setObject(Object object)
This method will automatically unwrap JsonValue
objects.
Transformers are inherited from the wrapped value. This value's pointer
remains unaffected.
public int size()
Copyright 2011-2015 ForgeRock AS.