public final class JsonValues extends Object
JsonValue
.Modifier and Type | Method and Description |
---|---|
static Class<?> |
asClass(JsonValue value)
Returns the class object associated with a named class or interface, using the thread
context class loader.
|
static <T> Expression<T> |
asExpression(JsonValue value,
Class<T> expectedType)
Returns a JSON value string value as an expression.
|
static <T> T |
asNewInstance(JsonValue value,
Class<T> type)
Creates a new instance of a named class.
|
static String |
evaluate(JsonValue value)
Evaluates the given JSON value string as an
Expression . |
static JsonValue |
evaluate(JsonValue value,
Logger logger)
Evaluates the given JSON value object, applying a
JsonTransformer
that will evaluate all String nodes. |
static JsonValue |
evaluateJsonStaticExpression(JsonValue value)
Evaluates the given JSON value using an Expression and wraps the returned value as a new JsonValue.
|
static JsonValue |
firstOf(JsonValue config,
String... names)
Returns, if the given JSON value contains one of the names, the first
defined JSON value, otherwise if the given JSON value does not match any
of the names, then a JsonValue encapsulating null is returned.
|
static JsonValue |
getWithDeprecation(JsonValue config,
Logger logger,
String name,
String... deprecatedNames)
Returns the named property from the provided JSON object, falling back to
zero or more deprecated property names.
|
static <T extends Enum<T>> |
ofEnum(Class<T> enumType)
|
static Function<JsonValue,Expression<String>,HeapException> |
ofExpression()
Returns a function for transforming JsonValues to expressions.
|
static <T> Function<JsonValue,T,HeapException> |
ofRequiredHeapObject(Heap heap,
Class<T> type)
|
static void |
warnForDeprecation(JsonValue config,
Logger logger,
String name,
String deprecatedName)
Issues a warning that the configuration property
oldName is
deprecated and that the property newName should be used instead. |
public static Class<?> asClass(JsonValue value)
null
, this method returns null
.value
- the value containing the class name string.JsonValueException
- if value is not a string or the named class could not be found.public static <T> T asNewInstance(JsonValue value, Class<T> type)
new
expression with an empty argument list. The class is initialized if it has
not already been initialized. If the value is null
, this method returns
null
.T
- the type of the new instance.value
- the value containing the class name string.type
- the type that the instantiated class should to resolve to.JsonValueException
- if the requested class could not be instantiated.public static <T> Expression<T> asExpression(JsonValue value, Class<T> expectedType)
null
, this
method returns null
.T
- expected result typevalue
- the JSON value containing the expression string.expectedType
- The expected result type of the expression.JsonValueException
- if the value is not a string or the value is not a valid expression.public static String evaluate(JsonValue value)
Expression
.value
- the JSON value containing the expression string.JsonValueException
- if the value is not a string or the value is not a valid string typed expression.public static JsonValue evaluate(JsonValue value, Logger logger)
JsonTransformer
that will evaluate all String nodes. Transformation is applied
recursively. Malformed expressions are ignored e.g: "$$$${{" and their values are not changed.
When an error occurs during the
evaluation of an expression, the value is set to null
because we
cannot differentiate successful evaluations or failed ones.
value
- The JSON value object to evaluate.logger
- The logger which should be used for warnings.JsonException
- If the value not a valid expression.public static JsonValue evaluateJsonStaticExpression(JsonValue value)
value
- the JSON value to be evaluated.JsonException
- if the expression cannot be evaluated (syntax error or resolution error).public static JsonValue firstOf(JsonValue config, String... names)
Uri uri = firstOf(config, "authorizeEndpoint", "authorize_endpoint").required().asURI();
config
- The JSON value where one of the selected names can be found.
Usually in a heaplet configuration for example.names
- Names of the attributes that you are looking for.public static Function<JsonValue,Expression<String>,HeapException> ofExpression()
public static <T> Function<JsonValue,T,HeapException> ofRequiredHeapObject(Heap heap, Class<T> type)
public static <T extends Enum<T>> Function<JsonValue,T,HeapException> ofEnum(Class<T> enumType)
public static JsonValue getWithDeprecation(JsonValue config, Logger logger, String name, String... deprecatedNames)
config
- The configuration object.logger
- The logger which should be used for deprecation warnings.name
- The non-deprecated property name.deprecatedNames
- The deprecated property names ordered from newest to oldest.public static void warnForDeprecation(JsonValue config, Logger logger, String name, String deprecatedName)
oldName
is
deprecated and that the property newName
should be used instead.config
- The configuration object.logger
- The logger which should be used for deprecation warnings.name
- The non-deprecated property name.deprecatedName
- The deprecated property name.Copyright 2011-2015 ForgeRock AS.