public class JsonUtils extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
JsonUtils.JsonDeserializationException
Wrapper exception for
JsonProcessingException as the other is a
checked exception and we don't want to check it everywhere. |
static class |
JsonUtils.JsonSerializationException
Wrapper exception for
JsonProcessingException as the other is a
checked exception and we don't want to check it everywhere. |
Constructor and Description |
---|
JsonUtils() |
Modifier and Type | Method and Description |
---|---|
static com.fasterxml.jackson.databind.JsonNode |
deserializeFromJson(java.lang.String json)
Deserializes a JSON string into a
JsonNode . |
static <T> T |
deserializeFromJson(java.lang.String json,
java.lang.Class<T> expectedClass)
Deserializes a JSON string.
|
static <T> T |
deserializeFromJson(java.lang.String json,
com.fasterxml.jackson.databind.JavaType expectedType)
Deserializes a JSON string.
|
static <T> T |
deserializeFromJson(java.lang.String json,
com.fasterxml.jackson.core.type.TypeReference<T> expectedType)
Deserializes a JSON string.
|
static <T> T |
deserializeFromJsonWithNullCheck(java.lang.String json,
java.lang.Class<T> expectedClass)
Deserializes a JSON string.
|
static <T> com.fasterxml.jackson.databind.JavaType |
getJavaListType(java.lang.Class<T> resultClass) |
static <T> com.fasterxml.jackson.databind.JavaType |
getJavaType(java.lang.Class<T> resultClass) |
static com.fasterxml.jackson.databind.ObjectMapper |
getObjectMapper() |
static java.util.Optional<com.fasterxml.jackson.databind.JsonNode> |
getWithCapitalizedOrLowercaseKey(com.fasterxml.jackson.databind.JsonNode jsonNode,
java.lang.String key)
Returns the json value or
null for the given key, while trying 1. |
static boolean |
isNotSerialized(java.lang.reflect.Field field) |
static boolean |
isValidJson(java.lang.String json)
Returns whether a string is a valid json or not.
|
static java.lang.String |
prettyPrintJSON(java.lang.String json)
Reformats a JSON string to be pretty printed.
|
static java.lang.String |
serializeToJSON(java.lang.Object object)
Serializes the given object to JSON.
|
static byte[] |
serializeToJSONByteArray(java.lang.Object object)
Serializes the given object to JSON as UTF-8 encoded byte array.
|
static java.lang.String |
serializeToJSONPrettyPrinted(java.lang.Object object)
Reformats a JSON string to be pretty printed.
|
public JsonUtils()
public static java.lang.String serializeToJSON(java.lang.Object object)
public static byte[] serializeToJSONByteArray(java.lang.Object object)
public static com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()
OBJECT_MAPPER
public static <T> com.fasterxml.jackson.databind.JavaType getJavaType(java.lang.Class<T> resultClass)
public static <T> com.fasterxml.jackson.databind.JavaType getJavaListType(java.lang.Class<T> resultClass)
public static <T> T deserializeFromJson(java.lang.String json, java.lang.Class<T> expectedClass) throws ConQATException
ConQATException
- if the input string could not be parsed as JSON or the class is
not constructible.public static <T> T deserializeFromJson(java.lang.String json, com.fasterxml.jackson.core.type.TypeReference<T> expectedType) throws ConQATException
ConQATException
- if the input string could not be parsed as JSON or the class is
not constructible.public static <T> T deserializeFromJson(java.lang.String json, com.fasterxml.jackson.databind.JavaType expectedType) throws ConQATException
ConQATException
- if the input string could not be parsed as JSON or the class is
not constructible.public static com.fasterxml.jackson.databind.JsonNode deserializeFromJson(java.lang.String json) throws ConQATException
JsonNode
.ConQATException
- if the input string could not be parsed as JSON or the class is
not constructible.public static <T> T deserializeFromJsonWithNullCheck(java.lang.String json, java.lang.Class<T> expectedClass) throws ConQATException
ConQATException
- if the input string could not be parsed as JSON, or the class is
not constructible, or the resulting object or one of its
attributes would be null.public static java.util.Optional<com.fasterxml.jackson.databind.JsonNode> getWithCapitalizedOrLowercaseKey(com.fasterxml.jackson.databind.JsonNode jsonNode, java.lang.String key)
null
for the given key, while trying 1. a
lowercase version of the key (e.g. 'project'), and 2. a capitalized version
of the lowercase key ('Project');public static boolean isValidJson(java.lang.String json)
public static java.lang.String prettyPrintJSON(java.lang.String json) throws ConQATException
ConQATException
public static java.lang.String serializeToJSONPrettyPrinted(java.lang.Object object) throws ConQATException
ConQATException
public static boolean isNotSerialized(java.lang.reflect.Field field)