public class JsonUtils extends Object
| Modifier and Type | Class and Description |
|---|---|
static interface |
JsonUtils.SupplierThrowingIOException<T> |
| Constructor and Description |
|---|
JsonUtils() |
| Modifier and Type | Method and Description |
|---|---|
static ObjectMapper |
createObjectMapper()
creates a new
ObjectMapper instance |
static ObjectMapper |
createObjectMapper(ModuleOptions options) |
static <T> T |
executing(JsonUtils.SupplierThrowingIOException<T> supplier) |
static <T> T |
fromInputStream(InputStream content,
Class<T> clazz)
deserializes the given json string to the given class
|
static <T> T |
fromJsonByteArray(byte[] content,
Class<T> clazz)
deserializes the given json string to the given class
|
static <T> T |
fromJsonNode(JsonNode jsonNode,
com.fasterxml.jackson.core.type.TypeReference<T> typeReference)
Reads a Java object from JsonNode data.
|
static <T> T |
fromJsonString(String content,
Class<T> clazz)
deserializes the given json string to the given class
|
static <T> T |
fromJsonString(String jsonAsString,
com.fasterxml.jackson.core.type.TypeReference<T> typeReference)
Reads a Java object from JSON data (String).
|
static ObjectMapper |
getConfiguredObjectMapper()
default
ObjectMapper |
static JsonNode |
parse(String jsonAsString)
Parses a String containing JSON data and produces a
JsonNode. |
static String |
prettyPrint(String json)
Pretty prints a given JSON string.
|
static byte[] |
toJsonByteArray(Object value)
serializes the given object to JSON as a byte array
|
static JsonNode |
toJsonNode(Object value)
Converts a commercetools Composable Commerce Java object to JSON as
JsonNode. |
static String |
toJsonString(Object value)
serializes the given object to JSON as a byte array
|
public JsonUtils()
public static ObjectMapper createObjectMapper()
ObjectMapper instancepublic static ObjectMapper createObjectMapper(ModuleOptions options)
options - configuration for jackson modules supplied by a ModuleSupplierpublic static byte[] toJsonByteArray(Object value) throws com.fasterxml.jackson.core.JsonProcessingException
value - object to be serializedcom.fasterxml.jackson.core.JsonProcessingException - serialization errorspublic static String toJsonString(Object value) throws com.fasterxml.jackson.core.JsonProcessingException
value - object to be serializedcom.fasterxml.jackson.core.JsonProcessingException - serialization errorspublic static <T> T fromJsonString(String content, Class<T> clazz)
T - type of the resultclazz - class to serialize tocontent - json as stringpublic static <T> T fromJsonString(String jsonAsString, com.fasterxml.jackson.core.type.TypeReference<T> typeReference)
T - the type of the resultjsonAsString - the JSON data which represents sth. of type <T>typeReference - the full generic type information about the object to createpublic static <T> T fromJsonNode(JsonNode jsonNode, com.fasterxml.jackson.core.type.TypeReference<T> typeReference)
T - the type of the resultjsonNode - the JSON data which represents sth. of type <T>typeReference - the full generic type information about the object to createpublic static JsonNode toJsonNode(Object value)
JsonNode.
If value is of type String and contains JSON data, that will be ignored, value will be treated as just any String.
If you want to parse a JSON String to a JsonNode use parse(java.lang.String) instead.
value - the object to convertpublic static JsonNode parse(String jsonAsString)
JsonNode.jsonAsString - json datapublic static <T> T fromJsonByteArray(byte[] content, Class<T> clazz)
T - type of the resultclazz - class to serialize tocontent - json as byte arrayJsonException - deserialization errorspublic static <T> T fromInputStream(InputStream content, Class<T> clazz)
T - type of the resultclazz - class to serialize tocontent - json as inputstreamJsonException - deserialization errorspublic static ObjectMapper getConfiguredObjectMapper()
ObjectMapperpublic static String prettyPrint(String json)
json - JSON code as String which should be formattedjson formattedpublic static <T> T executing(JsonUtils.SupplierThrowingIOException<T> supplier)