Package org.forgerock.http.util
Class Json
- java.lang.Object
-
- org.forgerock.http.util.Json
-
public final class Json extends Object
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
Nested Classes Modifier and Type Class Description static classJson.JsonValueModuleJackson Module that uses a mixin to make sure that aJsonValueinstance is serialized using its#getObject()value only.static classJson.LocalizableStringModuleJackson Module that adds a serializer forLocalizableString.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcheckJsonCompatibility(String trail, Object value)Verify that the given parameter object is of a JSON compatible type (recursively).static com.fasterxml.jackson.databind.ObjectWritermakeLocalizingObjectWriter(com.fasterxml.jackson.databind.ObjectMapper mapper, Request request)Make an object writer that contains the locales from the request for serialization ofLocalizableStringinstances.static com.fasterxml.jackson.databind.ObjectWritermakeLocalizingObjectWriter(com.fasterxml.jackson.databind.ObjectMapper mapper, PreferredLocales locales)Make an object writer that contains the provided locales for serialization ofLocalizableStringinstances.static ObjectreadJson(Reader reader)Parses to json the provided reader.static ObjectreadJson(String rawData)Parses to json the provided data.static ObjectreadJsonLenient(InputStream in)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 ObjectreadJsonLenient(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[]writeJson(Object objectToWrite)Writes the JSON content of the object passed in parameter.
-
-
-
Method Detail
-
checkJsonCompatibility
public static void checkJsonCompatibility(String trail, Object value)
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
public static Object readJson(String rawData) throws IOException
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,Booleanornull. - Throws:
IOException- If an exception occurs during parsing the data.- See Also:
readJson(Reader)
-
readJson
public static Object readJson(Reader reader) throws IOException
Parses to json the provided reader.- Parameters:
reader- The data to parse.- Returns:
- Any of
Map<String, Object>,List<Object>,Number,Booleanornull. - Throws:
IOException- If an exception occurs during parsing the data.
-
readJsonLenient
public static Object readJsonLenient(Reader reader) throws IOException
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,Booleanornull. - Throws:
IOException- If an error occurs during reading/parsing the data.
-
readJsonLenient
public static Object readJsonLenient(InputStream in) throws IOException
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,Booleanornull. - Throws:
IOException- If an error occurs during reading/parsing the data.
-
writeJson
public static byte[] writeJson(Object objectToWrite) throws IOException
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 MalformedHeaderExceptionMake an object writer that contains the locales from the request for serialization ofLocalizableStringinstances. The providedmapperwill be used to create the writer so that serialization configuration is not recreated.- Parameters:
mapper- TheObjectMapperto 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 ofLocalizableStringinstances. The providedmapperwill be used to create the writer so that serialization configuration is not recreated.- Parameters:
mapper- TheObjectMapperto obtain a writer from.locales- ThePreferredLocalesinstance to use for localization, ornull.- Returns:
- The configured
ObjectWriter.
-
-