Class JSONWriterUtil


  • public class JSONWriterUtil
    extends java.lang.Object
    JSON writer utilities

    Enables to specify a write mode while adding a JSON property. According to the provided write mode, the property value may be encoded through the XSS protection service

    Since:
    5.4
    • Field Detail

      • KEY_SUFFIX_XSS

        public static final java.lang.String KEY_SUFFIX_XSS
        Key suffix for XSS protected properties
        See Also:
        Constant Field Values
    • Constructor Detail

      • JSONWriterUtil

        public JSONWriterUtil()
    • Method Detail

      • put

        public static void put​(JSONObject object,
                               java.lang.String key,
                               java.lang.String value,
                               JSONWriterUtil.WriteMode writeMode,
                               XSSProtectionService xss)
                        throws JSONException
        Puts a value into a JSON object according to provided write mode.
        Parameters:
        object - JSON object
        key - Key to write
        value - Value to write
        writeMode - Write mode
        xss - XSS protection service
        Throws:
        JSONException - If value could not be put into the object
      • putOptional

        public static void putOptional​(JSONObject object,
                                       java.lang.String key,
                                       java.lang.String value,
                                       JSONWriterUtil.WriteMode writeMode,
                                       XSSProtectionService xss)
                                throws JSONException
        Puts an optional value into a JSON object according to provided write mode.
        Parameters:
        object - JSON object
        key - Key to write
        value - Value to write
        writeMode - Write mode
        xss - XSS protection service
        Throws:
        JSONException - If value could not be put into the object
      • write

        public static void write​(JSONWriter writer,
                                 java.lang.String key,
                                 java.lang.String value,
                                 JSONWriterUtil.WriteMode writeMode,
                                 XSSProtectionService xss)
                          throws JSONException
        Writes a value to JSON writer according to provided write mode.
        Parameters:
        writer - JSON writer
        key - Key to write
        value - Value to write
        writeMode - Write mode
        xss - XSS protection service
        Throws:
        JSONException - If value could not be written
      • writeOptional

        public static void writeOptional​(JSONWriter writer,
                                         java.lang.String key,
                                         java.lang.String value,
                                         JSONWriterUtil.WriteMode writeMode,
                                         XSSProtectionService xss)
                                  throws JSONException
        Writes an optional value to JSON writer according to provided write mode.
        Parameters:
        writer - JSON writer
        key - Key to write
        value - Value to write
        writeMode - Write mode
        xss - XSS protection service
        Throws:
        JSONException - If value could not be written