Class JsonValues
JsonValue
.-
Method Summary
Modifier and TypeMethodDescriptionstatic Class<?>
Returns the class object associated with a named class or interface, using the thread context class loader.static Function<JsonValue,
Bindings, JsonValueException> bindings()
Returns a function that will create some bindings based of a Map-basedJsonValue
.static Function<JsonValue,
Bindings, JsonValueException> Returns a function that will create some bindings based of a Map-basedJsonValue
.Returns aSecretReference.constant(Secret)
from aGenericSecret
attribute value.Returns a function that transforms the JSON value to aEncryptionMethod
object.static Function<JsonValue,
JsonValue, JsonValueException> Returns a function that will evaluate all String nodes.static Function<JsonValue,
JsonValue, JsonValueException> Returns a function that will evaluate all String nodes.evaluatedAsync
(Bindings bindings) Returns an async function that will evaluate all String nodes.expectedType
(Class<T> type, Function<JsonValue, T, E> adapter) Allows to usedefaultTo
in an heaplet configuration to retrieve an object.static <T> Function<JsonValue,
Expression<T>, JsonValueException> expression
(Class<T> type) Returns a function for transforming JsonValues to expressions.static <T> Function<JsonValue,
Expression<T>, JsonValueException> expression
(Class<T> type, Bindings bindings) Returns a function for transforming JsonValues to expressions.static JsonValue
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, org.slf4j.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 Function<JsonValue,
Instant, JsonValueException> instant()
static Function<JsonValue,
Duration, JsonValueException> static <T> Function<JsonValue,
LeftValueExpression<T>, JsonValueException> leftValueExpression
(Class<T> type) Returns a function for transforming JsonValues to left-value expressions.Returns a function that transform a JSON node value into a list of adapted instances.static <T> Function<JsonValue,
T, HeapException> lookupOrCreateHeapObject
(Heap heap, Class<T> type) Returns the JSON value as aMap
containing values whose type is specified by a transformation function.static Function<JsonValue,
Optional<JsonValue>, JsonValueException> optional()
static <T> Function<JsonValue,
T, HeapException> optionalHeapObject
(Heap heap, Class<T> type) static <T> Function<JsonValue,
Optional<T>, JsonValueException> optionalOf
(Function<JsonValue, T, JsonValueException> delegate) Returns a wrapping function returning anOptional
result of the givendelegate
function.static Function<JsonValue,
Integer, JsonValueException> static Function<JsonValue,
Duration, JsonValueException> positiveLimitedDuration
(Duration defaultDuration) Transform duration configuration to aDuration
, enforcing that its value is positive (non-zero) and limited.Returns a function that transforms the JSON value to aProperties
object.static <S extends Secret>
Function<JsonValue,Purpose<S>, JsonValueException> static JsonValue
Builds aJsonValue
from the given URL.static Function<JsonValue,
JsonValue, JsonValueException> Displays a custom message when the required attribute is not present in the configuration.static <T> Function<JsonValue,
T, HeapException> requiredHeapObject
(Heap heap, Class<T> type) static Function<JsonValue,
JsonValue, JsonValueException> Returns a function that will resolve the field $location.static Function<JsonValue,
JsonValue, JsonValueException> resolvedLocation
(Bindings bindings) Returns a function that will resolve the field $location.secretPropertyFormat
(Heap heap) Returns aSecretPropertyFormat
object from aJsonValue
.static <S extends Secret>
Function<JsonValue,SecretReference<S>, JsonValueException> secretReferenceOf
(Function<JsonValue, Purpose<S>, JsonValueException> purposeTransformer, SecretsProvider secretsProvider) Returns a function that returns aSecretReference
for thePurpose
represented by the givenString
value label and known to the suppliedSecretsProvider
.static Function<JsonValue,
JsonValue, JsonValueException> Returns the JsonValue with its value ended by a slash.Returns the JSON value as aStream
containing objects whose type (and value) is specified by a transformation function.tokenized
(org.forgerock.config.resolvers.PropertyResolver propertyResolver) Returns a function performing deep token substitution and object coercion ($ "functions").static void
warnForDeprecation
(JsonValue config, org.slf4j.Logger logger, String name, String deprecatedName) Issues a warning that the configuration propertyoldName
is deprecated and that the propertynewName
should be used instead.
-
Method Details
-
slashEnded
Returns the JsonValue with its value ended by a slash. This could be useful when working on uris. Example of use:config.get("openamUri").as(evaluatedWithHeapProperties()) .required() .as(slashEnded()) .as(uri());
- Returns:
- the string value always ended with a slash.
- Throws:
JsonValueException
- If the JSON value is not a string.
-
asClass
Returns the class object associated with a named class or interface, using the thread context class loader. If the value isnull
, this method returnsnull
.- Parameters:
value
- the value containing the class name string.- Returns:
- the class object with the specified name.
- Throws:
JsonValueException
- if value is not a string or the named class could not be found.
-
resolvedLocation
Returns a function that will resolve the field $location.- Returns:
- a function that will resolve the field $location.
- See Also:
-
resolvedLocation
Returns a function that will resolve the field $location.- Parameters:
bindings
- The bindings used when evaluating the $location value- Returns:
- a function that will resolve the field $location.
- See Also:
-
evaluated
Returns a function 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.- Returns:
- a function to evaluate String nodes of a
JsonValue
-
evaluated
Returns a function 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.- Parameters:
bindings
- the bindings to use when evaluating the found expressions- Returns:
- a function to evaluate String nodes of a
JsonValue
-
evaluatedAsync
public static AsyncFunction<JsonValue,JsonValue, evaluatedAsyncNeverThrowsException> (Bindings bindings) Returns an async function 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.- Parameters:
bindings
- the bindings to use when evaluating the found expressions- Returns:
- an async function to evaluate String nodes of a
JsonValue
-
firstOf
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. Example of use:Uri uri = firstOf(config, "authorizeEndpoint", "authorize_endpoint").required().asURI();
- Parameters:
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.- Returns:
- the specified item JSON value or JsonValue encapsulating null if none were found.
-
instant
- Returns:
- a function that will create an
Instant
representation of a timestamp in seconds. - Throws:
JsonValueException
- if the value is not a number.
-
javaDuration
- Returns:
- a
Duration
-
positiveLimitedDuration
public static Function<JsonValue,Duration, positiveLimitedDurationJsonValueException> (Duration defaultDuration) Transform duration configuration to aDuration
, enforcing that its value is positive (non-zero) and limited. That is to say, the value must not be unlimited (Duration.UNLIMITED
). This is to support e.g. expiry times. Should the value be zero or unlimited, the supplieddefaultDuration
is set instead.- Parameters:
defaultDuration
- the default duration to use should the supplied duration evaluate to zero or unlimited- Returns:
- Function capable of transforming configuration to a
Duration
-
leftValueExpression
public static <T> Function<JsonValue,LeftValueExpression<T>, leftValueExpressionJsonValueException> (Class<T> type) Returns a function for transforming JsonValues to left-value expressions.- Type Parameters:
T
- expected result type- Parameters:
type
- The expected result type of the expression.- Returns:
- A function for transforming JsonValues to left-value expressions.
-
expression
Returns a function for transforming JsonValues to expressions.- Type Parameters:
T
- expected result type- Parameters:
type
- The expected result type of the expression.- Returns:
- A function for transforming JsonValues to expressions.
-
expression
public static <T> Function<JsonValue,Expression<T>, expressionJsonValueException> (Class<T> type, Bindings bindings) Returns a function for transforming JsonValues to expressions.- Type Parameters:
T
- expected result type- Parameters:
type
- The expected result type of the expression.bindings
- The initial bindings used when evaluated this expression- Returns:
- A function for transforming JsonValues to expressions.
-
bindings
Returns a function that will create some bindings based of a Map-basedJsonValue
.- Returns:
- a function that will create some bindings based of a Map-based
JsonValue
.
-
bindings
Returns a function that will create some bindings based of a Map-basedJsonValue
.- Parameters:
bindings
- The initial bindings used when evaluated the- Returns:
- a function that will create some bindings based of a Map-based
JsonValue
.
-
lookupOrCreateHeapObject
public static <T> Function<JsonValue,T, lookupOrCreateHeapObjectHeapException> (Heap heap, Class<T> type) Returns aFunction
that will lookup into the provided heap and its parents for an object named by the providedJsonValue
declaration. If no such object is found then it's created in the provided heap as an anonymous object.- Type Parameters:
T
- expected object type- Parameters:
heap
- the heap to query for references resolutiontype
- expected object type- Returns:
- a
Function
that will create the object if it's not found into the provided heap or its parents.
-
requiredHeapObject
-
optionalHeapObject
-
getWithDeprecation
public static JsonValue getWithDeprecation(JsonValue config, org.slf4j.Logger logger, String name, String... deprecatedNames) Returns the named property from the provided JSON object, falling back to zero or more deprecated property names. This method will log a warning if only a deprecated property is found or if two equivalent property names are found.- Parameters:
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.- Returns:
- The request property.
-
warnForDeprecation
public static void warnForDeprecation(JsonValue config, org.slf4j.Logger logger, String name, String deprecatedName) Issues a warning that the configuration propertyoldName
is deprecated and that the propertynewName
should be used instead.- Parameters:
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.
-
readJson
Builds aJsonValue
from the given URL.- Parameters:
resource
- the URL to read the JSON from- Returns:
- a
JsonValue
built from the resource URL - Throws:
IOException
- If an error occurs while trying to read the JSON
-
tokenized
public static Function<JsonValue,JsonValue, tokenizedorg.forgerock.config.resolvers.SubstitutionException> (org.forgerock.config.resolvers.PropertyResolver propertyResolver) Returns a function performing deep token substitution and object coercion ($ "functions").- Parameters:
propertyResolver
- Resolver to use for token substitution- Returns:
- a function performing deep token substitution and object coercion ($ "functions").
-
expectedType
public static <T,E extends Exception> Function<JsonValue,T, expectedTypeE> (Class<T> type, Function<JsonValue, T, E> adapter) Allows to usedefaultTo
in an heaplet configuration to retrieve an object.Example:
config.get("keyStore").defaultTo(myObject) .as(expectedType(KeyStore.class, optionalHeapObject(heap, KeyStore.class)));
- Type Parameters:
T
- The generic type of the object returned by the adapter.E
- The generic exception thrown by the adapter if something wrong happens.- Parameters:
type
- The class of the object.adapter
- The function used to to retrieve the object.- Returns:
- The object.
-
optional
-
optionalOf
public static <T> Function<JsonValue,Optional<T>, optionalOfJsonValueException> (Function<JsonValue, T, JsonValueException> delegate) Returns a wrapping function returning anOptional
result of the givendelegate
function.- Type Parameters:
T
- expected result type- Parameters:
delegate
- delegate transformation function- Returns:
- An
Optional
result of the givendelegate
function.
-
purposeOf
public static <S extends Secret> Function<JsonValue,Purpose<S>, purposeOfJsonValueException> (Class<S> type) - Type Parameters:
S
- The type of thePurpose
.- Parameters:
type
- ThePurpose
type (i.e:GenericSecret
, etc...).- Returns:
- a purpose of the selected type or
null
if the value is null.
-
secretReferenceOf
public static <S extends Secret> Function<JsonValue,SecretReference<S>, secretReferenceOfJsonValueException> (Function<JsonValue, Purpose<S>, JsonValueException> purposeTransformer, SecretsProvider secretsProvider) Returns a function that returns aSecretReference
for thePurpose
represented by the givenString
value label and known to the suppliedSecretsProvider
.- Type Parameters:
S
- The type of thePurpose
andSecret
to be referenced- Parameters:
purposeTransformer
- Function capable of transforming aPurpose
from a suppliedString
value representing the labelsecretsProvider
-SecretsProvider
capable of providing the requiredSecret
- Returns:
- a secret reference of the selected type or
null
if the value is null.
-
constantSecretReference
public static Function<JsonValue,SecretReference<GenericSecret>, constantSecretReference()JsonValueException> Returns aSecretReference.constant(Secret)
from aGenericSecret
attribute value.- Returns:
- a constant secret reference of the
GenericSecret
ornull
if the value is null.
-
required
Displays a custom message when the required attribute is not present in the configuration.- Parameters:
message
- The message to display when the required attribute is not present.- Returns:
- a
JsonValueException
if the attribute is not present in the configuration with a custom message.
-
listOf
public static <T,E extends Exception> Function<JsonValue,List<T>, listOfE> (Function<JsonValue, T, E> adapter) Returns a function that transform a JSON node value into a list of adapted instances.Accepts formats such as:
{ "null": null, "singleton": node, "multi": [ nodes... ] }
A
null
value results in an immutable empty list.A unique, singleton primitive value is returned as a singleton list (modifiable).
An array of values returns a list of adapted objects (of the size of the initial JSON array)
- Type Parameters:
T
- List's item typeE
- exception type- Parameters:
adapter
- adaptation function- Returns:
- a list (never
null
)
-
streamOf
public static <V,E extends Exception> Function<JsonValue,Stream<V>, streamOfE> (Function<JsonValue, V, E> transformFunction) Returns the JSON value as aStream
containing objects whose type (and value) is specified by a transformation function. If the value is not a collection, this method returnsStream.empty()
. It is up to the transformation function to transform/enforce source types of the elements in the Json source collection. If any of the elements of the list are not of the appropriate type, or the type-transformation cannot occur, the exception specified by the transformation function is thrown.- Type Parameters:
V
- the type of elements in this listE
- the type of exception thrown by the transformation function- Parameters:
transformFunction
- aFunction
to transform an element of the JsonValue list to the desired type- Returns:
- the streamed value, or
Stream.empty()
if not a collection. - Throws:
NullPointerException
- iftransformFunction
isnull
.
-
properties
Returns a function that transforms the JSON value to aProperties
object. The values to transform must represent an object or map of keys and values, where the values are of typeString
.- Returns:
- a
Properties
object repreentation, not-null
-
encryptionMethod
Returns a function that transforms the JSON value to aEncryptionMethod
object.- Returns:
- a
EncryptionMethod
, notnull
.
-
secretPropertyFormat
public static Function<JsonValue,SecretPropertyFormat, secretPropertyFormatJsonValueException> (Heap heap) Returns aSecretPropertyFormat
object from aJsonValue
.- Parameters:
heap
- The heap used to resolve the reference to theSecretPropertyFormat
.- Returns:
- a
SecretPropertyFormat
.
-
positiveInteger
- Returns:
- A positive
Integer
.
-
mapOf
public static <V,E extends Exception> Function<JsonValue,Map<String, mapOfV>, E> (Function<JsonValue, V, E> transformFunction) Returns the JSON value as aMap
containing values whose type is specified by a transformation function. If the value isnull
, this method returnsnull
. It is up to the transformation function to transform/enforce source types of the elements in the Json source collection. If called on an object which is not a map, this method will return null. If any of the elements of the collection are not of the appropriate type, or the type-transformation cannot occur, the exception specified by the transformation function is thrown.- Type Parameters:
V
- the type of map values in this setE
- the type of exception thrown by the transformation function- Parameters:
transformFunction
- aFunction
to transform an element of the JsonValue map to the desired type- Returns:
- the map value, or
null
if no value. - Throws:
NullPointerException
- iftransformFunction
isnull
.
-