Package com.day.cq.commons
Class JSONWriterUtil
java.lang.Object
com.day.cq.commons.JSONWriterUtil
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
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidput(JSONObject object, String key, String value, JSONWriterUtil.WriteMode writeMode, XSSProtectionService xss) Puts a value into a JSON object according to provided write mode.static voidputOptional(JSONObject object, String key, String value, JSONWriterUtil.WriteMode writeMode, XSSProtectionService xss) Puts an optional value into a JSON object according to provided write mode.static voidwrite(JSONWriter writer, String key, String value, JSONWriterUtil.WriteMode writeMode, XSSProtectionService xss) Writes a value to JSON writer according to provided write mode.static voidwriteOptional(JSONWriter writer, String key, String value, JSONWriterUtil.WriteMode writeMode, XSSProtectionService xss) Writes an optional value to JSON writer according to provided write mode.
-
Field Details
-
KEY_SUFFIX_XSS
Key suffix for XSS protected properties- See Also:
-
-
Constructor Details
-
JSONWriterUtil
public JSONWriterUtil()
-
-
Method Details
-
put
public static void put(JSONObject object, String key, String value, JSONWriterUtil.WriteMode writeMode, XSSProtectionService xss) throws JSONException Puts a value into a JSON object according to provided write mode.- Parameters:
object- JSON objectkey- Key to writevalue- Value to writewriteMode- Write modexss- XSS protection service- Throws:
JSONException- If value could not be put into the object
-
putOptional
public static void putOptional(JSONObject object, String key, 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 objectkey- Key to writevalue- Value to writewriteMode- Write modexss- XSS protection service- Throws:
JSONException- If value could not be put into the object
-
write
public static void write(JSONWriter writer, String key, String value, JSONWriterUtil.WriteMode writeMode, XSSProtectionService xss) throws JSONException Writes a value to JSON writer according to provided write mode.- Parameters:
writer- JSON writerkey- Key to writevalue- Value to writewriteMode- Write modexss- XSS protection service- Throws:
JSONException- If value could not be written
-
writeOptional
public static void writeOptional(JSONWriter writer, String key, String value, JSONWriterUtil.WriteMode writeMode, XSSProtectionService xss) throws JSONException Writes an optional value to JSON writer according to provided write mode.- Parameters:
writer- JSON writerkey- Key to writevalue- Value to writewriteMode- Write modexss- XSS protection service- Throws:
JSONException- If value could not be written
-