Class 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).
    • 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 object
        value - 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, Boolean or null.
        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, Boolean or null.
        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, Boolean or null.
        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, Boolean or null.
        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 MalformedHeaderException
        Make an object writer that contains the locales from the request for serialization of LocalizableString instances. The provided mapper will be used to create the writer so that serialization configuration is not recreated.
        Parameters:
        mapper - The ObjectMapper 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 of LocalizableString instances. The provided mapper will be used to create the writer so that serialization configuration is not recreated.
        Parameters:
        mapper - The ObjectMapper to obtain a writer from.
        locales - The PreferredLocales instance to use for localization, or null.
        Returns:
        The configured ObjectWriter.