Package org.forgerock.http.util
Class Json
java.lang.Object
org.forgerock.http.util.Json
Provides read and write JSON capabilities.
Can check if an object reference is JSON-compatible (expressed as primitive values, list/array and map).
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Jackson Module that uses a mixin to make sure that aJsonValue
instance is serialized using its#getObject()
value only.static class
Jackson Module that adds a serializer forLocalizableString
. -
Method Summary
Modifier and TypeMethodDescriptionstatic void
checkJsonCompatibility
(String trail, Object value) Verify that the given parameter object is of a JSON compatible type (recursively).static com.fasterxml.jackson.databind.ObjectWriter
makeLocalizingObjectWriter
(com.fasterxml.jackson.databind.ObjectMapper mapper, Request request) Make an object writer that contains the locales from the request for serialization ofLocalizableString
instances.static com.fasterxml.jackson.databind.ObjectWriter
makeLocalizingObjectWriter
(com.fasterxml.jackson.databind.ObjectMapper mapper, PreferredLocales locales) Make an object writer that contains the provided locales for serialization ofLocalizableString
instances.static Object
Parses to json the provided reader.static Object
Parses to json the provided data.static Object
This function it's only used to read our configuration files and allows JSON files to contain non strict JSON such as comments or single quotes.static Object
readJsonLenient
(Reader reader) This function it's only used to read our configuration files and allows JSON files to contain non strict JSON such as comments or single quotes.static byte[]
Writes the JSON content of the object passed in parameter.
-
Method Details
-
checkJsonCompatibility
Verify that the given parameter object is of a JSON compatible type (recursively). If no exception is thrown that means the parameter can be used in the JWT session (that is a JSON value).- Parameters:
trail
- pointer to the verified objectvalue
- object to verify
-
readJson
Parses to json the provided data.- Parameters:
rawData
- The data as a string to read and parse.- Returns:
- Any of
Map<String, Object>
,List<Object>
,Number
,Boolean
ornull
. - Throws:
IOException
- If an exception occurs during parsing the data.- See Also:
-
readJson
Parses to json the provided reader.- Parameters:
reader
- The data to parse.- Returns:
- Any of
Map<String, Object>
,List<Object>
,Number
,Boolean
ornull
. - Throws:
IOException
- If an exception occurs during parsing the data.
-
readJsonLenient
This function it's only used to read our configuration files and allows JSON files to contain non strict JSON such as comments or single quotes.- Parameters:
reader
- The stream of data to parse.- Returns:
- Any of
Map<String, Object>
,List<Object>
,Number
,Boolean
ornull
. - Throws:
IOException
- If an error occurs during reading/parsing the data.
-
readJsonLenient
This function it's only used to read our configuration files and allows JSON files to contain non strict JSON such as comments or single quotes.- Parameters:
in
- The input stream containing the json.- Returns:
- Any of
Map<String, Object>
,List<Object>
,Number
,Boolean
ornull
. - Throws:
IOException
- If an error occurs during reading/parsing the data.
-
writeJson
Writes the JSON content of the object passed in parameter.- Parameters:
objectToWrite
- The object we want to serialize as JSON output. The- Returns:
- the Json output as a byte array.
- Throws:
IOException
- If an error occurs during writing/mapping content.
-
makeLocalizingObjectWriter
public static com.fasterxml.jackson.databind.ObjectWriter makeLocalizingObjectWriter(com.fasterxml.jackson.databind.ObjectMapper mapper, Request request) throws MalformedHeaderException Make an object writer that contains the locales from the request for serialization ofLocalizableString
instances. The providedmapper
will be used to create the writer so that serialization configuration is not recreated.- Parameters:
mapper
- TheObjectMapper
to obtain a writer from.request
- The CHF request.- Returns:
- The configured
ObjectWriter
. - Throws:
MalformedHeaderException
- If the Accept-Language header is malformed.
-
makeLocalizingObjectWriter
public static com.fasterxml.jackson.databind.ObjectWriter makeLocalizingObjectWriter(com.fasterxml.jackson.databind.ObjectMapper mapper, PreferredLocales locales) Make an object writer that contains the provided locales for serialization ofLocalizableString
instances. The providedmapper
will be used to create the writer so that serialization configuration is not recreated.- Parameters:
mapper
- TheObjectMapper
to obtain a writer from.locales
- ThePreferredLocales
instance to use for localization, ornull
.- Returns:
- The configured
ObjectWriter
.
-