Message Security Layer (MSL)

com.netflix.msl.util
Class JsonUtils

java.lang.Object
  extended by com.netflix.msl.util.JsonUtils

public class JsonUtils
extends Object

JSON processing utility functions.


Field Summary
private static char CHAR_EQUALS
           
private static char CHAR_MINUS
           
private static char CHAR_PLUS
          Base64 characters.
private static char CHAR_SLASH
           
private static char CHAR_UNDERSCORE
           
private static Charset UTF_8
          Encoding charset.
 
Constructor Summary
JsonUtils()
           
 
Method Summary
static byte[] b64urlDecode(String data)
          URL-safe Base64 decode data that has no padding characters.
static String b64urlDecodeToString(String data)
          URL-safe Base64 decode data as UTF-8 that has no padding characters.
static String b64urlEncode(byte[] data)
          URL-safe Base64 encode data without padding characters.
static String b64urlEncode(String s)
          URL-safe Base64 encode data as UTF-8 without padding characters.
static JSONArray createArray(Collection<?> c)
          Create a JSON array from a collection of objects that are either one of the accepted types: Boolean, JSONArray, JSONObject, Number, String, or the JSONObject.NULL object or turn any JSONString into a JSONObject.
static boolean equals(JSONArray ja1, JSONArray ja2)
          Performs a deep comparison of two JSON arrays for equality.
static boolean equals(JSONObject jo1, JSONObject jo2)
          Performs a deep comparison of two JSON objects for equivalence.
static boolean equalSets(JSONArray ja1, JSONArray ja2)
          Performs a shallow comparison of two JSON arrays for set equality.
static boolean objectEquals(String js1, String js2)
          Performs a deep comparison of two JSON objects.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UTF_8

private static final Charset UTF_8
Encoding charset.


CHAR_PLUS

private static final char CHAR_PLUS
Base64 characters.

See Also:
Constant Field Values

CHAR_MINUS

private static final char CHAR_MINUS
See Also:
Constant Field Values

CHAR_SLASH

private static final char CHAR_SLASH
See Also:
Constant Field Values

CHAR_UNDERSCORE

private static final char CHAR_UNDERSCORE
See Also:
Constant Field Values

CHAR_EQUALS

private static final char CHAR_EQUALS
See Also:
Constant Field Values
Constructor Detail

JsonUtils

public JsonUtils()
Method Detail

b64urlEncode

public static String b64urlEncode(String s)
URL-safe Base64 encode data as UTF-8 without padding characters.

Parameters:
s - the value to Base64 encode.
Returns:
the Base64 encoded data.

b64urlEncode

public static String b64urlEncode(byte[] data)
URL-safe Base64 encode data without padding characters.

Parameters:
data - the value to Base64 encode.
Returns:
the Base64 encoded data.

b64urlDecode

public static byte[] b64urlDecode(String data)
URL-safe Base64 decode data that has no padding characters.

Parameters:
data - the Base64 encoded data.
Returns:
the decoded data or null if there is an error decoding.

b64urlDecodeToString

public static String b64urlDecodeToString(String data)
URL-safe Base64 decode data as UTF-8 that has no padding characters.

Parameters:
data - the Base64 encoded data.
Returns:
the decoded data as a UTF-8 string.

createArray

public static JSONArray createArray(Collection<?> c)
                             throws JSONException
Create a JSON array from a collection of objects that are either one of the accepted types: Boolean, JSONArray, JSONObject, Number, String, or the JSONObject.NULL object or turn any JSONString into a JSONObject.

Parameters:
c - a collection of JSON-compatible objects.
Throws:
JSONException - if a JSONString cannot be encoded properly or an unsupported object is encountered.

objectEquals

public static boolean objectEquals(String js1,
                                   String js2)
                            throws JSONException
Performs a deep comparison of two JSON objects.

Parameters:
js1 - first JSON object string representation.
js2 - second JSON object string representation.
Returns:
true if the strings are equivalent JSON objects or arrays.
Throws:
JSONException - if there is an error parsing the JSON.
See Also:
equals(JSONObject, JSONObject)

equals

public static boolean equals(JSONObject jo1,
                             JSONObject jo2)
                      throws JSONException
Performs a deep comparison of two JSON objects for equivalence. JSON objects are equivalent if they have the same name/value pairs. Also, two JSON object references are considered equal if both are null.

Parameters:
jo1 - first JSON object.
jo2 - second JSON object.
Returns:
true if the JSON objects are equivalent.
Throws:
JSONException - if there is an error parsing the JSON.

equals

public static boolean equals(JSONArray ja1,
                             JSONArray ja2)
                      throws JSONException
Performs a deep comparison of two JSON arrays for equality. Two JSON arrays are considered equal if both arrays contain the same number of elements, and all corresponding pairs of elements in the two arrays are equal. In other words, two JSON arrays are equal if they contain the same elements in the same order. Also, two JSON array references are considered equal if both are null.

Parameters:
ja1 - first JSON array. May be null.
ja2 - second JSON array. May be null.
Returns:
true if the JSON arrays are equal.
Throws:
JSONException - if there is an error parsing the JSON.

equalSets

public static boolean equalSets(JSONArray ja1,
                                JSONArray ja2)
                         throws JSONException
Performs a shallow comparison of two JSON arrays for set equality. Two JSON arrays are considered set-equal if both arrays contain the same number of elements and all elements found in one array are also found in the other. In other words, two JSON arrays are set-equal if they contain the same elements in the any order. Also, two JSON array references are considered set-equal if both are null.

Parameters:
ja1 - first JSON array. May be null.
ja2 - second JSON array. May be null.
Returns:
true if the JSON arrays are set-equal.
Throws:
JSONException - if there is an error parsing the JSON.

Message Security Layer (MSL)

Copyright © 2014 Netflix, Inc. All Rights Reserved.