Package com.itextpdf.commons.utils
Class JsonUtil
java.lang.Object
com.itextpdf.commons.utils.JsonUtil
Utility class for JSON serialization and deserialization operations. Not for public use.
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanareTwoJsonObjectEquals(String expectedString, String toCompare) Compares two json strings without considering the order of the elements.staticT deserializeFromStream(InputStream content, com.fasterxml.jackson.core.type.TypeReference objectType) Deserializes passed JSON stream to object with passed type.staticT deserializeFromStream(InputStream content, com.fasterxml.jackson.databind.JavaType objectType) Deserializes passed JSON stream to object with passed type.staticT deserializeFromStream(InputStream content, Class objectType) Deserializes passed JSON stream to object with passed type.staticT deserializeFromString(String content, com.fasterxml.jackson.core.type.TypeReference objectType) Deserializes passed JSON string to object with passed type.staticT deserializeFromString(String content, com.fasterxml.jackson.databind.JavaType objectType) Deserializes passed JSON string to object with passed type.staticT deserializeFromString(String content, Class objectType) Deserializes passed JSON string to object with passed type.static voidserializeToMinimalStream(OutputStream outputStream, Object value) Serializes passed object to minimal JSON without spaces and line breaks and writes it into provided stream.static StringserializeToMinimalString(Object value) Serializes passed object to minimal JSON string without spaces and line breaks.static voidserializeToStream(OutputStream outputStream, Object value) Serializes passed object to provided JSON output stream.static StringserializeToString(Object value) Serializes passed object to JSON string.
-
Method Details
-
areTwoJsonObjectEquals
public static boolean areTwoJsonObjectEquals(String expectedString, String toCompare) throws IOException Compares two json strings without considering the order of the elements.- Parameters:
-
expectedString- expected json string -
toCompare- string for comparison - Returns:
- true if two json string are equals, false otherwise
- Throws:
-
IOException- if an I/O error occurs
-
serializeToStream
Serializes passed object to provided JSON output stream.- Parameters:
-
outputStream- stream to which the object will be serialized -
value- the object which will be serialized
-
serializeToString
Serializes passed object to JSON string.- Parameters:
-
value- the object which will be serialized - Returns:
-
the JSON string representation of passed object or
nullif it is impossible to serialize to JSON
-
serializeToMinimalStream
Serializes passed object to minimal JSON without spaces and line breaks and writes it into provided stream.- Parameters:
-
outputStream- stream to which the object will be serialized -
value- the object which will be serialized
-
serializeToMinimalString
Serializes passed object to minimal JSON string without spaces and line breaks.- Parameters:
-
value- the object which will be serialized - Returns:
-
the minimal JSON string representation of passed object or
nullif it is impossible to serialize to JSON
-
deserializeFromStream
Deserializes passed JSON stream to object with passed type.- Type Parameters:
-
T- the type of object which will be deserialized - Parameters:
-
content- the JSON stream which represent object -
objectType- the class of object asClasswhich will be deserialized - Returns:
-
the deserialized object or
nullif operation of deserialization is impossible
-
deserializeFromStream
public staticT deserializeFromStream (InputStream content, com.fasterxml.jackson.core.type.TypeReference objectType) Deserializes passed JSON stream to object with passed type.- Type Parameters:
-
T- the type of object which will be deserialized - Parameters:
-
content- the JSON stream which represent object -
objectType- the class of object asTypeReferencewhich will be deserialized - Returns:
-
the deserialized object or
nullif operation of deserialization is impossible
-
deserializeFromStream
public staticT deserializeFromStream (InputStream content, com.fasterxml.jackson.databind.JavaType objectType) Deserializes passed JSON stream to object with passed type.- Type Parameters:
-
T- the type of object which will be deserialized - Parameters:
-
content- the JSON stream which represent object -
objectType- the class of object asJavaTypewhich will be deserialized - Returns:
-
the deserialized object or
nullif operation of deserialization is impossible
-
deserializeFromString
Deserializes passed JSON string to object with passed type.- Type Parameters:
-
T- the type of object which will be deserialized - Parameters:
-
content- the JSON string which represent object -
objectType- the class of object asClasswhich will be deserialized - Returns:
-
the deserialized object or
nullif operation of deserialization is impossible
-
deserializeFromString
public staticT deserializeFromString (String content, com.fasterxml.jackson.core.type.TypeReference objectType) Deserializes passed JSON string to object with passed type.- Type Parameters:
-
T- the type of object which will be deserialized - Parameters:
-
content- the JSON string which represent object -
objectType- the class of object asTypeReferencewhich will be deserialized - Returns:
-
the deserialized object or
nullif operation of deserialization is impossible
-
deserializeFromString
public staticT deserializeFromString (String content, com.fasterxml.jackson.databind.JavaType objectType) Deserializes passed JSON string to object with passed type.- Type Parameters:
-
T- the type of object which will be deserialized - Parameters:
-
content- the JSON string which represent object -
objectType- the class of object asJavaTypewhich will be deserialized - Returns:
-
the deserialized object or
nullif operation of deserialization is impossible
-