Class JsonValues
- java.lang.Object
- 
- org.forgerock.openig.util.JsonValues
 
- 
- 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static Class<?>asClass(JsonValue value)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>bindings(Bindings bindings)Returns a function that will create some bindings based of a Map-basedJsonValue.static Function<JsonValue,SecretReference<GenericSecret>,JsonValueException>constantSecretReference()Returns aSecretReference.constant(Secret)from aGenericSecretattribute value.static Function<JsonValue,EncryptionMethod,JsonValueException>encryptionMethod()Returns a function that transforms the JSON value to aEncryptionMethodobject.static Function<JsonValue,JsonValue,JsonValueException>evaluated()Returns a function that will evaluate all String nodes.static Function<JsonValue,JsonValue,JsonValueException>evaluated(Bindings bindings)Returns a function that will evaluate all String nodes.static AsyncFunction<JsonValue,JsonValue,NeverThrowsException>evaluatedAsync(Bindings bindings)Returns an async function that will evaluate all String nodes.static <T,E extends Exception>
 Function<JsonValue,T,E>expectedType(Class<T> type, Function<JsonValue,T,E> adapter)Allows to usedefaultToin 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 JsonValuefirstOf(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 JsonValuegetWithDeprecation(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,String,JsonValueException>heapObjectNameOrPointer()Returns a function that will look for the name of the object.static Function<JsonValue,Instant,JsonValueException>instant()static Function<JsonValue,Duration,JsonValueException>javaDuration()static <T> Function<JsonValue,LeftValueExpression<T>,JsonValueException>leftValueExpression(Class<T> type)Returns a function for transforming JsonValues to left-value expressions.static <T,E extends Exception>
 Function<JsonValue,List<T>,E>listOf(Function<JsonValue,T,E> adapter)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)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 anOptionalresult of the givendelegatefunction.static Function<JsonValue,Integer,JsonValueException>positiveInteger()static Function<JsonValue,Properties,JsonValueException>properties()Returns a function that transforms the JSON value to aPropertiesobject.static <S extends Secret>
 Function<JsonValue,Purpose<S>,JsonValueException>purposeOf(Class<S> type)static JsonValuereadJson(URL resource)Builds aJsonValuefrom the given URL.static Function<JsonValue,JsonValue,JsonValueException>required(String message)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>resolvedLocation()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.static Function<JsonValue,SecretPropertyFormat,JsonValueException>secretPropertyFormat(Heap heap)Returns aSecretPropertyFormatobject 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 aSecretReferencefor thePurposerepresented by the givenStringvalue label and known to the suppliedSecretsProvider.static Function<JsonValue,JsonValue,JsonValueException>slashEnded()Returns the JsonValue with its value ended by a slash.static <V,E extends Exception>
 Function<JsonValue,Stream<V>,E>streamOf(Function<JsonValue,V,E> transformFunction)Returns the JSON value as aStreamcontaining objects whose type (and value) is specified by a transformation function.static Function<JsonValue,JsonValue,org.forgerock.config.resolvers.SubstitutionException>tokenized(org.forgerock.config.resolvers.PropertyResolver propertyResolver)Returns a function performing deep token substitution and object coercion ($ "functions").static voidwarnForDeprecation(JsonValue config, org.slf4j.Logger logger, String name, String deprecatedName)Issues a warning that the configuration propertyoldNameis deprecated and that the propertynewNameshould be used instead.
 
- 
- 
- 
Method Detail- 
slashEndedpublic static Function<JsonValue,JsonValue,JsonValueException> 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.
 
 - 
asClasspublic static Class<?> asClass(JsonValue value) 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.
 
 - 
resolvedLocationpublic static Function<JsonValue,JsonValue,JsonValueException> resolvedLocation() Returns a function that will resolve the field $location.- Returns:
- a function that will resolve the field $location.
- See Also:
- ResolveLocationJsonValueFunction
 
 - 
resolvedLocationpublic static Function<JsonValue,JsonValue,JsonValueException> resolvedLocation(Bindings bindings) 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:
- ResolveLocationJsonValueFunction
 
 - 
heapObjectNameOrPointerpublic static Function<JsonValue,String,JsonValueException> heapObjectNameOrPointer() Returns a function that will look for the name of the object. It infers a locally unique name for the given object declaration. If a name attribute is provided, simply return its value as name, otherwise builds a unique name composed of both the declaration JSON pointer (map to the location within the JSON file) and the value of the type attribute (ease to identify the object).The following declaration would return Inline: { "name": "Inline", "type": "Router" }And this one would return {WelcomeHandler}/heap/objects/0/config/defaultHandler: { "type": "WelcomeHandler" }- Returns:
- the name of the heap object or the pointer to that object if it is anonymous.
 
 - 
evaluatedpublic static Function<JsonValue,JsonValue,JsonValueException> 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 nullbecause we cannot differentiate successful evaluations or failed ones.- Returns:
- a function to evaluate String nodes of a JsonValue
 
 - 
evaluatedpublic static Function<JsonValue,JsonValue,JsonValueException> evaluated(Bindings bindings) 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 nullbecause 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
 
 - 
evaluatedAsyncpublic static AsyncFunction<JsonValue,JsonValue,NeverThrowsException> evaluatedAsync(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 nullbecause 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
 
 - 
firstOfpublic 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. 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.
 
 - 
instantpublic static Function<JsonValue,Instant,JsonValueException> instant() - Returns:
- a function that will create an Instantrepresentation of a timestamp in seconds.
- Throws:
- JsonValueException- if the value is not a number.
 
 - 
javaDurationpublic static Function<JsonValue,Duration,JsonValueException> javaDuration() - Returns:
- a Duration
 
 - 
leftValueExpressionpublic static <T> Function<JsonValue,LeftValueExpression<T>,JsonValueException> leftValueExpression(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.
 
 - 
expressionpublic static <T> Function<JsonValue,Expression<T>,JsonValueException> expression(Class<T> type) 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.
 
 - 
expressionpublic static <T> Function<JsonValue,Expression<T>,JsonValueException> expression(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.
 
 - 
bindingspublic static Function<JsonValue,Bindings,JsonValueException> 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.
 
 - 
bindingspublic static Function<JsonValue,Bindings,JsonValueException> bindings(Bindings 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.
 
 - 
lookupOrCreateHeapObjectpublic static <T> Function<JsonValue,T,HeapException> lookupOrCreateHeapObject(Heap heap, Class<T> type) Returns aFunctionthat will lookup into the provided heap and its parents for an object named by the providedJsonValuedeclaration. If no such object is found then it's created in the provided heap.- Type Parameters:
- T- expected object type
- Parameters:
- heap- the heap to query for references resolution
- type- expected object type
- Returns:
- a Functionthat will create the object if it's not found into the provided heap or its parents.
 
 - 
requiredHeapObjectpublic static <T> Function<JsonValue,T,HeapException> requiredHeapObject(Heap heap, Class<T> type) 
 - 
optionalHeapObjectpublic static <T> Function<JsonValue,T,HeapException> optionalHeapObject(Heap heap, Class<T> type) 
 - 
getWithDeprecationpublic 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.
 
 - 
warnForDeprecationpublic static void warnForDeprecation(JsonValue config, org.slf4j.Logger logger, String name, String deprecatedName) Issues a warning that the configuration propertyoldNameis deprecated and that the propertynewNameshould 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.
 
 - 
readJsonpublic static JsonValue readJson(URL resource) throws IOException Builds aJsonValuefrom the given URL.- Parameters:
- resource- the URL to read the JSON from
- Returns:
- a JsonValuebuilt from the resource URL
- Throws:
- IOException- If an error occurs while trying to read the JSON
 
 - 
tokenizedpublic static Function<JsonValue,JsonValue,org.forgerock.config.resolvers.SubstitutionException> tokenized(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").
 
 - 
expectedTypepublic static <T,E extends Exception> Function<JsonValue,T,E> expectedType(Class<T> type, Function<JsonValue,T,E> adapter) Allows to usedefaultToin 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.
 
 - 
optionalpublic static Function<JsonValue,Optional<JsonValue>,JsonValueException> optional() 
 - 
optionalOfpublic static <T> Function<JsonValue,Optional<T>,JsonValueException> optionalOf(Function<JsonValue,T,JsonValueException> delegate) Returns a wrapping function returning anOptionalresult of the givendelegatefunction.- Type Parameters:
- T- expected result type
- Parameters:
- delegate- delegate transformation function
- Returns:
- An Optionalresult of the givendelegatefunction.
 
 - 
purposeOfpublic static <S extends Secret> Function<JsonValue,Purpose<S>,JsonValueException> purposeOf(Class<S> type) - Type Parameters:
- S- The type of the- Purpose.
- Parameters:
- type- The- Purposetype (i.e:- GenericSecret, etc...).
- Returns:
- a purpose of the selected type or nullif the value is null.
 
 - 
secretReferenceOfpublic static <S extends Secret> Function<JsonValue,SecretReference<S>,JsonValueException> secretReferenceOf(Function<JsonValue,Purpose<S>,JsonValueException> purposeTransformer, SecretsProvider secretsProvider) Returns a function that returns aSecretReferencefor thePurposerepresented by the givenStringvalue label and known to the suppliedSecretsProvider.- Type Parameters:
- S- The type of the- Purposeand- Secretto be referenced
- Parameters:
- purposeTransformer- Function capable of transforming a- Purposefrom a supplied- Stringvalue representing the label
- secretsProvider-- SecretsProvidercapable of providing the required- Secret
- Returns:
- a secret reference of the selected type or nullif the value is null.
 
 - 
constantSecretReferencepublic static Function<JsonValue,SecretReference<GenericSecret>,JsonValueException> constantSecretReference() Returns aSecretReference.constant(Secret)from aGenericSecretattribute value.- Returns:
- a constant secret reference of the GenericSecretornullif the value is null.
 
 - 
requiredpublic static Function<JsonValue,JsonValue,JsonValueException> required(String message) 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 JsonValueExceptionif the attribute is not present in the configuration with a custom message.
 
 - 
listOfpublic static <T,E extends Exception> Function<JsonValue,List<T>,E> listOf(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 nullvalue 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 type
- E- exception type
- Parameters:
- adapter- adaptation function
- Returns:
- a list (never null)
 
 - 
streamOfpublic static <V,E extends Exception> Function<JsonValue,Stream<V>,E> streamOf(Function<JsonValue,V,E> transformFunction) Returns the JSON value as aStreamcontaining 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 list
- E- the type of exception thrown by the transformation function
- Parameters:
- transformFunction- a- Functionto transform an element of the JsonValue list to the desired type
- Returns:
- the streamed value, or Stream.empty()if not a collection.
- Throws:
- NullPointerException- if- transformFunctionis- null.
 
 - 
propertiespublic static Function<JsonValue,Properties,JsonValueException> properties() Returns a function that transforms the JSON value to aPropertiesobject. The values to transform must represent an object or map of keys and values, where the values are of typeString.- Returns:
- a Propertiesobject repreentation, not-null
 
 - 
encryptionMethodpublic static Function<JsonValue,EncryptionMethod,JsonValueException> encryptionMethod() Returns a function that transforms the JSON value to aEncryptionMethodobject.- Returns:
- a EncryptionMethod, notnull.
 
 - 
secretPropertyFormatpublic static Function<JsonValue,SecretPropertyFormat,JsonValueException> secretPropertyFormat(Heap heap) Returns aSecretPropertyFormatobject from aJsonValue.- Parameters:
- heap- The heap used to resolve the reference to the- SecretPropertyFormat.
- Returns:
- a SecretPropertyFormat.
 
 - 
positiveIntegerpublic static Function<JsonValue,Integer,JsonValueException> positiveInteger() - Returns:
- A positive Integer.
 
 
- 
 
-