Class JsonUtil
java.lang.Object
com.itextpdf.commons.utils.JsonUtil
Utility class for JSON serialization and deserialization operations. Not for public use.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classThis class is used to define a custom separator and array indent to achieve the same serialization in Java and .NET.private static classThis class is used to define a printer which serialize to minimal string, without extra spaces and line breaks. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanareTwoJsonObjectEquals(String expectedString, String toCompare) Compares two json strings without considering the order of the elements.private static com.fasterxml.jackson.databind.ObjectWritercreateAndConfigureObjectWriter(com.fasterxml.jackson.core.util.DefaultPrettyPrinter prettyPrinter) Creates and configure object writer with givenDefaultPrettyPrinter.static <T> TdeserializeFromStream(InputStream content, com.fasterxml.jackson.core.type.TypeReference<T> objectType) Deserializes passed JSON stream to object with passed type.static <T> TdeserializeFromStream(InputStream content, com.fasterxml.jackson.databind.JavaType objectType) Deserializes passed JSON stream to object with passed type.static <T> TdeserializeFromStream(InputStream content, Class<T> objectType) Deserializes passed JSON stream to object with passed type.static <T> TdeserializeFromString(String content, com.fasterxml.jackson.core.type.TypeReference<T> objectType) Deserializes passed JSON string to object with passed type.static <T> TdeserializeFromString(String content, com.fasterxml.jackson.databind.JavaType objectType) Deserializes passed JSON string to object with passed type.static <T> TdeserializeFromString(String content, Class<T> 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.private static voidserializeToStream(OutputStream outputStream, Object value, com.fasterxml.jackson.core.util.DefaultPrettyPrinter prettyPrinter) Serializes passed object to provided JSON output stream.static StringserializeToString(Object value) Serializes passed object to JSON string.private static StringserializeToString(Object value, com.fasterxml.jackson.core.util.DefaultPrettyPrinter prettyPrinter) Serializes passed object to JSON string.
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER
-
-
Constructor Details
-
JsonUtil
private JsonUtil()
-
-
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 stringtoCompare- 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 serializedvalue- the object which will be serialized
-
serializeToString
-
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 serializedvalue- 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 objectobjectType- the class of object asClasswhich will be deserialized- Returns:
- the deserialized object or
nullif operation of deserialization is impossible
-
deserializeFromStream
public static <T> T deserializeFromStream(InputStream content, com.fasterxml.jackson.core.type.TypeReference<T> 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 objectobjectType- the class of object asTypeReferencewhich will be deserialized- Returns:
- the deserialized object or
nullif operation of deserialization is impossible
-
deserializeFromStream
public static <T> T 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 objectobjectType- 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 objectobjectType- the class of object asClasswhich will be deserialized- Returns:
- the deserialized object or
nullif operation of deserialization is impossible
-
deserializeFromString
public static <T> T deserializeFromString(String content, com.fasterxml.jackson.core.type.TypeReference<T> 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 objectobjectType- the class of object asTypeReferencewhich will be deserialized- Returns:
- the deserialized object or
nullif operation of deserialization is impossible
-
deserializeFromString
public static <T> T 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 objectobjectType- the class of object asJavaTypewhich will be deserialized- Returns:
- the deserialized object or
nullif operation of deserialization is impossible
-
createAndConfigureObjectWriter
private static com.fasterxml.jackson.databind.ObjectWriter createAndConfigureObjectWriter(com.fasterxml.jackson.core.util.DefaultPrettyPrinter prettyPrinter) Creates and configure object writer with givenDefaultPrettyPrinter.- Parameters:
prettyPrinter- specified pretty printer for indentation- Returns:
- configured object writer
-
serializeToStream
private static void serializeToStream(OutputStream outputStream, Object value, com.fasterxml.jackson.core.util.DefaultPrettyPrinter prettyPrinter) Serializes passed object to provided JSON output stream.- Parameters:
outputStream- stream to which the object will be serializedvalue- the object which will be serializedprettyPrinter- specified pretty printer for indentation
-
serializeToString
private static String serializeToString(Object value, com.fasterxml.jackson.core.util.DefaultPrettyPrinter prettyPrinter) Serializes passed object to JSON string.- Parameters:
value- the object which will be serializedprettyPrinter- specified pretty printer for indentation- Returns:
- the JSON string representation of passed object or
nullif it is impossible to serialize to JSON
-