public class JsonObjectAccessor
extends java.lang.Object
JsonAccessException
which is a RuntimeException.Constructor and Description |
---|
JsonObjectAccessor(JsonObject jsonObject)
Creates a new accessor based on the given JSON object.
|
Modifier and Type | Method and Description |
---|---|
protected TimeValue |
asTimeValue(java.lang.Long value,
TimeUnit timeUnit) |
static JsonObjectAccessor |
create()
Creates an accessor on a new empty
JsonObject . |
static JsonObjectAccessor |
create(JsonObject jsonObject)
Creates an accessor based on the given JSON object.
|
java.util.List<java.lang.String> |
getFieldNames()
Returns all field names present in the underlying JSON object (maybe empty but never null).
|
JsonObject |
getJsonObject()
Returns the underlying JSON object.
|
protected java.lang.Long |
getLongValueOf(java.lang.String name) |
protected java.lang.Long |
getLongValueOf(java.lang.String name,
java.lang.String targetTypeName) |
protected NaturalNumber |
getNaturalNumberValueOf(java.lang.String name) |
java.math.BigDecimal |
getOptionalBigDecimalValue(IStringConstant name)
Returns either the value associated to the given name or null.
|
java.math.BigDecimal |
getOptionalBigDecimalValue(java.lang.String name)
Returns either the value associated to the given name or null.
|
java.lang.Boolean |
getOptionalBooleanValue(IStringConstant name)
Returns either the value associated to the given name or null.
|
java.lang.Boolean |
getOptionalBooleanValue(java.lang.String name)
Returns either the value associated to the given name or null.
|
java.lang.Integer |
getOptionalIntegerValue(IStringConstant name)
Returns either the value associated to the given name or null.
|
java.lang.Integer |
getOptionalIntegerValue(java.lang.String name)
Returns either the value associated to the given name or null.
|
JsonArray |
getOptionalJsonArrayValue(IStringConstant name)
Returns either the value associated to the given name or null.
|
JsonArray |
getOptionalJsonArrayValue(java.lang.String name)
Returns either the value associated to the given name or null.
|
JsonObjectAccessor |
getOptionalJsonObjectAccessorValue(IStringConstant name)
Returns either the value associated to the given name or null.
|
JsonObjectAccessor |
getOptionalJsonObjectAccessorValue(java.lang.String name)
Returns either the value associated to the given name or null.
|
JsonObject |
getOptionalJsonObjectValue(IStringConstant name)
Returns either the value associated to the given name or null.
|
JsonObject |
getOptionalJsonObjectValue(java.lang.String name)
Returns either the value associated to the given name or null.
|
java.lang.Long |
getOptionalLongValue(IStringConstant name)
Returns either the value associated to the given name or null.
|
java.lang.Long |
getOptionalLongValue(java.lang.String name)
Returns either the value associated to the given name or null.
|
NaturalNumber |
getOptionalNaturalNumberValue(IStringConstant name)
Returns either the value associated to the given name or null.
|
NaturalNumber |
getOptionalNaturalNumberValue(java.lang.String name)
Returns either the value associated to the given name or null.
|
java.lang.Object |
getOptionalRawValue(IStringConstant name)
Returns either the value associated to the given name or null.
|
java.lang.Object |
getOptionalRawValue(java.lang.String name)
Returns either the value associated to the given name or null.
|
java.lang.String[] |
getOptionalStringArrayValue(IStringConstant name)
Returns either the value associated to the given name or null.
|
java.lang.String[] |
getOptionalStringArrayValue(java.lang.String name)
Returns either the value associated to the given name or null.
|
java.lang.String |
getOptionalStringValue(IStringConstant name)
Returns either the value associated to the given name or null.
|
java.lang.String |
getOptionalStringValue(java.lang.String name)
Returns either the value associated to the given name or null.
|
TimeValue |
getOptionalTimeValue(IStringConstant name,
TimeUnit timeUnit)
|
TimeValue |
getOptionalTimeValue(java.lang.String name,
TimeUnit timeUnit)
|
<T> T |
getOptionalTypedValue(IStringConstant name,
java.lang.Class<T> type)
Returns either the value associated to the given name or null if not preset.
|
<T> T |
getOptionalTypedValue(java.lang.String name,
java.lang.Class<T> type)
Returns either the value associated to the given name or null if not preset.
|
java.lang.Object |
getRawValueOf(IStringConstant name,
boolean isRequired) |
java.lang.Object |
getRawValueOf(java.lang.String name,
boolean isRequired) |
java.math.BigDecimal |
getRequiredBigDecimalValue(IStringConstant name)
Returns either the value associated to the given name or throws a
JsonAccessException
if the value is not present or of another type that expected (according to the return type of this method). |
java.math.BigDecimal |
getRequiredBigDecimalValue(java.lang.String name)
Returns either the value associated to the given name or throws a
JsonAccessException
if the value is not present or of another type that expected (according to the return type of this method). |
java.lang.Boolean |
getRequiredBooleanValue(IStringConstant name)
Returns either the value associated to the given name or throws a
JsonAccessException
if the value is not present or of another type that expected (according to the return type of this method). |
java.lang.Boolean |
getRequiredBooleanValue(java.lang.String name)
Returns either the value associated to the given name or throws a
JsonAccessException
if the value is not present or of another type that expected (according to the return type of this method). |
java.lang.Integer |
getRequiredIntegerValue(IStringConstant name)
Returns either the value associated to the given name or throws a
JsonAccessException
if the value is not present or of another type that expected (according to the return type of this method). |
java.lang.Integer |
getRequiredIntegerValue(java.lang.String name)
Returns either the value associated to the given name or throws a
JsonAccessException
if the value is not present or of another type that expected (according to the return type of this method). |
JsonArray |
getRequiredJsonArrayValue(IStringConstant name)
Returns either the value associated to the given name or throws a
JsonAccessException
if the value is not present or of another type that expected (according to the return type of this method). |
JsonArray |
getRequiredJsonArrayValue(java.lang.String name)
Returns either the value associated to the given name or throws a
JsonAccessException
if the value is not present or of another type that expected (according to the return type of this method). |
JsonObjectAccessor |
getRequiredJsonObjectAccessorValue(IStringConstant name)
Returns either the value associated to the given name or throws a
JsonAccessException
if the value is not present or of another type that expected (according to the return type of this method). |
JsonObjectAccessor |
getRequiredJsonObjectAccessorValue(java.lang.String name)
Returns either the value associated to the given name or throws a
JsonAccessException
if the value is not present or of another type that expected (according to the return type of this method). |
JsonObject |
getRequiredJsonObjectValue(IStringConstant name)
Returns either the value associated to the given name or throws a
JsonAccessException
if the value is not present or of another type that expected (according to the return type of this method). |
JsonObject |
getRequiredJsonObjectValue(java.lang.String name)
Returns either the value associated to the given name or throws a
JsonAccessException
if the value is not present or of another type that expected (according to the return type of this method). |
java.lang.Long |
getRequiredLongValue(IStringConstant name)
Returns either the value associated to the given name or throws a
JsonAccessException
if the value is not present or of another type that expected (according to the return type of this method). |
java.lang.Long |
getRequiredLongValue(java.lang.String name)
Returns either the value associated to the given name or throws a
JsonAccessException
if the value is not present or of another type that expected (according to the return type of this method). |
NaturalNumber |
getRequiredNaturalNumberValue(IStringConstant name)
Returns either the value associated to the given name or throws a
JsonAccessException
if the value is not present or of another type that expected (according to the return type of this method). |
NaturalNumber |
getRequiredNaturalNumberValue(java.lang.String name)
Returns either the value associated to the given name or throws a
JsonAccessException
if the value is not present or of another type that expected (according to the return type of this method). |
java.lang.Object |
getRequiredRawValue(IStringConstant name)
Returns either the value associated to the given name or throws a
JsonAccessException
if the value is not present. |
java.lang.Object |
getRequiredRawValue(java.lang.String name)
Returns either the value associated to the given name or throws a
JsonAccessException
if the value is not present. |
java.lang.String[] |
getRequiredStringArrayValue(IStringConstant name)
Returns either the value associated to the given name or throws a
JsonAccessException
if the value is not present or of another type that expected (according to the return type of this method). |
java.lang.String[] |
getRequiredStringArrayValue(java.lang.String name)
Returns either the value associated to the given name or throws a
JsonAccessException
if the value is not present or of another type that expected (according to the return type of this method). |
java.lang.String |
getRequiredStringValue(IStringConstant name)
Returns either the value associated to the given name or throws a
JsonAccessException
if the value is not present or of another type that expected (according to the return type of this method). |
java.lang.String |
getRequiredStringValue(java.lang.String name)
Returns either the value associated to the given name or throws a
JsonAccessException
if the value is not present or of another type that expected (according to the return type of this method). |
TimeValue |
getRequiredTimeValue(IStringConstant name,
TimeUnit timeUnit)
Returns either the value associated to the given name or throws a
JsonAccessException
if the value is not present or of another type that expected (according to the return type of this method). |
TimeValue |
getRequiredTimeValue(java.lang.String name,
TimeUnit timeUnit)
Returns either the value associated to the given name or throws a
JsonAccessException
if the value is not present or of another type that expected (according to the return type of this method). |
<T> T |
getRequiredTypedValue(IStringConstant name,
java.lang.Class<T> type)
Returns either the value associated to the given name or @throws JsonAccessException
if the value is not of the specified type or not present.
|
<T> T |
getRequiredTypedValue(java.lang.String name,
java.lang.Class<T> type)
Returns either the value associated to the given name or @throws JsonAccessException
if the value is not of the specified type or not present.
|
protected java.lang.String[] |
getStringArray(java.lang.String name,
boolean isRequired) |
<T> T |
getTypedValueOf(IStringConstant name,
java.lang.Class<T> type,
boolean isRequired) |
<T> T |
getTypedValueOf(java.lang.String name,
java.lang.Class<T> type,
boolean isRequired) |
boolean |
hasField(IStringConstant name)
Returns whether or not this JSON object contains a field with the given name.
|
boolean |
hasField(java.lang.String name)
Returns whether or not this JSON object contains a field with the given name.
|
boolean |
isEmpty()
Returns true if the underlying JSON object contains no field at all.
|
JsonObjectAccessor |
setFieldValue(IStringConstant name,
java.lang.Object value)
Sets the field with the given name to the specified value.
|
JsonObjectAccessor |
setFieldValue(java.lang.String name,
java.lang.Object value)
Sets the field with the given name to the specified value.
|
void |
signalRequiredFieldMissing(java.lang.String fieldName) |
public JsonObjectAccessor(JsonObject jsonObject)
jsonObject
- The JSON object to be accessed (must not be null).
throws IllegalArgumentException if the given jsonObject is null.public static JsonObjectAccessor create()
JsonObject
.public static JsonObjectAccessor create(JsonObject jsonObject)
jsonObject
- The JSON object to be accessed (must not be null).
throws IllegalArgumentException if the given jsonObject is null.public JsonObject getJsonObject()
public java.util.List<java.lang.String> getFieldNames()
public JsonObjectAccessor getRequiredJsonObjectAccessorValue(IStringConstant name)
JsonAccessException
if the value is not present or of another type that expected (according to the return type of this method).public JsonObjectAccessor getRequiredJsonObjectAccessorValue(java.lang.String name)
JsonAccessException
if the value is not present or of another type that expected (according to the return type of this method).public JsonObject getRequiredJsonObjectValue(IStringConstant name)
JsonAccessException
if the value is not present or of another type that expected (according to the return type of this method).public JsonObject getRequiredJsonObjectValue(java.lang.String name)
JsonAccessException
if the value is not present or of another type that expected (according to the return type of this method).public JsonArray getRequiredJsonArrayValue(IStringConstant name)
JsonAccessException
if the value is not present or of another type that expected (according to the return type of this method).public JsonArray getRequiredJsonArrayValue(java.lang.String name)
JsonAccessException
if the value is not present or of another type that expected (according to the return type of this method).public java.lang.String getRequiredStringValue(IStringConstant name)
JsonAccessException
if the value is not present or of another type that expected (according to the return type of this method).public java.lang.String getRequiredStringValue(java.lang.String name)
JsonAccessException
if the value is not present or of another type that expected (according to the return type of this method).public java.lang.String[] getRequiredStringArrayValue(IStringConstant name)
JsonAccessException
if the value is not present or of another type that expected (according to the return type of this method).public java.lang.String[] getRequiredStringArrayValue(java.lang.String name)
JsonAccessException
if the value is not present or of another type that expected (according to the return type of this method).public java.lang.Boolean getRequiredBooleanValue(IStringConstant name)
JsonAccessException
if the value is not present or of another type that expected (according to the return type of this method).public java.lang.Boolean getRequiredBooleanValue(java.lang.String name)
JsonAccessException
if the value is not present or of another type that expected (according to the return type of this method).public java.lang.Integer getRequiredIntegerValue(IStringConstant name)
JsonAccessException
if the value is not present or of another type that expected (according to the return type of this method).public java.lang.Integer getRequiredIntegerValue(java.lang.String name)
JsonAccessException
if the value is not present or of another type that expected (according to the return type of this method).public java.lang.Long getRequiredLongValue(IStringConstant name)
JsonAccessException
if the value is not present or of another type that expected (according to the return type of this method).public java.lang.Long getRequiredLongValue(java.lang.String name)
JsonAccessException
if the value is not present or of another type that expected (according to the return type of this method).public java.math.BigDecimal getRequiredBigDecimalValue(IStringConstant name)
JsonAccessException
if the value is not present or of another type that expected (according to the return type of this method).public java.math.BigDecimal getRequiredBigDecimalValue(java.lang.String name)
JsonAccessException
if the value is not present or of another type that expected (according to the return type of this method).public NaturalNumber getRequiredNaturalNumberValue(IStringConstant name)
JsonAccessException
if the value is not present or of another type that expected (according to the return type of this method).public NaturalNumber getRequiredNaturalNumberValue(java.lang.String name)
JsonAccessException
if the value is not present or of another type that expected (according to the return type of this method).public TimeValue getRequiredTimeValue(IStringConstant name, TimeUnit timeUnit)
JsonAccessException
if the value is not present or of another type that expected (according to the return type of this method).public TimeValue getRequiredTimeValue(java.lang.String name, TimeUnit timeUnit)
JsonAccessException
if the value is not present or of another type that expected (according to the return type of this method).public java.lang.Object getRequiredRawValue(IStringConstant name)
JsonAccessException
if the value is not present.public java.lang.Object getRequiredRawValue(java.lang.String name)
JsonAccessException
if the value is not present.public JsonObjectAccessor getOptionalJsonObjectAccessorValue(IStringConstant name)
public JsonObjectAccessor getOptionalJsonObjectAccessorValue(java.lang.String name)
public JsonObject getOptionalJsonObjectValue(IStringConstant name)
public JsonObject getOptionalJsonObjectValue(java.lang.String name)
public JsonArray getOptionalJsonArrayValue(IStringConstant name)
public JsonArray getOptionalJsonArrayValue(java.lang.String name)
public java.lang.String getOptionalStringValue(IStringConstant name)
public java.lang.String getOptionalStringValue(java.lang.String name)
public java.lang.String[] getOptionalStringArrayValue(IStringConstant name)
public java.lang.String[] getOptionalStringArrayValue(java.lang.String name)
public java.lang.Boolean getOptionalBooleanValue(IStringConstant name)
public java.lang.Boolean getOptionalBooleanValue(java.lang.String name)
public java.lang.Integer getOptionalIntegerValue(IStringConstant name)
public java.lang.Integer getOptionalIntegerValue(java.lang.String name)
public java.lang.Long getOptionalLongValue(IStringConstant name)
public java.lang.Long getOptionalLongValue(java.lang.String name)
public java.math.BigDecimal getOptionalBigDecimalValue(IStringConstant name)
public java.math.BigDecimal getOptionalBigDecimalValue(java.lang.String name)
public NaturalNumber getOptionalNaturalNumberValue(IStringConstant name)
public NaturalNumber getOptionalNaturalNumberValue(java.lang.String name)
public TimeValue getOptionalTimeValue(IStringConstant name, TimeUnit timeUnit)
name
- The name of the field (must not be null).timeUnit
- The time unit of the value found in the object (must not be null).public TimeValue getOptionalTimeValue(java.lang.String name, TimeUnit timeUnit)
name
- The name of the field (must not be null).timeUnit
- The time unit of the value found in the object (must not be null).public java.lang.Object getOptionalRawValue(IStringConstant name)
public java.lang.Object getOptionalRawValue(java.lang.String name)
public <T> T getOptionalTypedValue(IStringConstant name, java.lang.Class<T> type)
JsonAccessException
- if the value is not of the specified type.public <T> T getOptionalTypedValue(java.lang.String name, java.lang.Class<T> type)
JsonAccessException
- if the value is not of the specified type.public <T> T getRequiredTypedValue(IStringConstant name, java.lang.Class<T> type)
public <T> T getRequiredTypedValue(java.lang.String name, java.lang.Class<T> type)
public <T> T getTypedValueOf(IStringConstant name, java.lang.Class<T> type, boolean isRequired)
public <T> T getTypedValueOf(java.lang.String name, java.lang.Class<T> type, boolean isRequired)
public java.lang.Object getRawValueOf(IStringConstant name, boolean isRequired)
public java.lang.Object getRawValueOf(java.lang.String name, boolean isRequired)
public JsonObjectAccessor setFieldValue(java.lang.String name, java.lang.Object value)
name
- The name of the field.value
- The value to be set.public JsonObjectAccessor setFieldValue(IStringConstant name, java.lang.Object value)
name
- The name of the field.value
- The value to be set.public boolean hasField(java.lang.String name)
public boolean hasField(IStringConstant name)
public boolean isEmpty()
public void signalRequiredFieldMissing(java.lang.String fieldName) throws JsonAccessException
JsonAccessException
protected java.lang.String[] getStringArray(java.lang.String name, boolean isRequired)
protected NaturalNumber getNaturalNumberValueOf(java.lang.String name)
protected java.lang.Long getLongValueOf(java.lang.String name)
protected java.lang.Long getLongValueOf(java.lang.String name, java.lang.String targetTypeName)