Package pl.edu.icm.unity
Class JsonUtil
java.lang.Object
pl.edu.icm.unity.JsonUtil
Simplifies JSON parsing a little bit
- Author:
- K. Benedyczak
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
getNullable
(com.fasterxml.jackson.databind.JsonNode src, String name) asgetWithDef(JsonNode, String, String)
with the last argument (default) == nullstatic String
getWithDef
(com.fasterxml.jackson.databind.JsonNode src, String name, String def) Safely gets a string value from node.static boolean
static com.fasterxml.jackson.databind.node.ObjectNode
parse
(byte[] contents) static com.fasterxml.jackson.databind.node.ObjectNode
static <T> T
static <T> List<T>
parseToList
(String contents, Class<T> clazz) static String
serialize
(com.fasterxml.jackson.databind.JsonNode node) static byte[]
serialize2Bytes
(com.fasterxml.jackson.databind.JsonNode node) static String
serializeHumanReadable
(com.fasterxml.jackson.databind.JsonNode node) static com.fasterxml.jackson.databind.JsonNode
toJsonNode
(Object value) static String
toJsonString
(Object value)
-
Constructor Details
-
JsonUtil
public JsonUtil()
-
-
Method Details
-
getNullable
asgetWithDef(JsonNode, String, String)
with the last argument (default) == null- Parameters:
src
-name
-- Returns:
-
getWithDef
public static String getWithDef(com.fasterxml.jackson.databind.JsonNode src, String name, String def) Safely gets a string value from node. if undefined then given default is returned. If node is null, then null is defined.- Parameters:
src
-name
-def
-- Returns:
-
notNull
- Parameters:
src
-name
-- Returns:
- true only if the given field exists and is not set to null
-
parse
-
parse
public static com.fasterxml.jackson.databind.node.ObjectNode parse(byte[] contents) -
serialize
-
serializeHumanReadable
-
serialize2Bytes
public static byte[] serialize2Bytes(com.fasterxml.jackson.databind.JsonNode node) -
parse
-
parseToList
-
toJsonString
-
toJsonNode
-