Package pl.edu.icm.unity
Class JsonUtil
- java.lang.Object
-
- pl.edu.icm.unity.JsonUtil
-
public class JsonUtil extends Object
Simplifies JSON parsing a little bit- Author:
- K. Benedyczak
-
-
Constructor Summary
Constructors Constructor Description JsonUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringgetNullable(com.fasterxml.jackson.databind.JsonNode src, String name)asgetWithDef(JsonNode, String, String)with the last argument (default) == nullstatic StringgetWithDef(com.fasterxml.jackson.databind.JsonNode src, String name, String def)Safely gets a string value from node.static booleannotNull(com.fasterxml.jackson.databind.JsonNode src, String name)static com.fasterxml.jackson.databind.node.ObjectNodeparse(byte[] contents)static com.fasterxml.jackson.databind.node.ObjectNodeparse(String contents)static <T> Tparse(String contents, Class<T> clazz)static <T> List<T>parseToList(String contents, Class<T> clazz)static Stringserialize(com.fasterxml.jackson.databind.JsonNode node)static byte[]serialize2Bytes(com.fasterxml.jackson.databind.JsonNode node)static StringserializeHumanReadable(com.fasterxml.jackson.databind.JsonNode node)static com.fasterxml.jackson.databind.JsonNodetoJsonNode(Object value)static StringtoJsonString(Object value)
-
-
-
Method Detail
-
getNullable
public static String getNullable(com.fasterxml.jackson.databind.JsonNode src, String name)
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
public static boolean notNull(com.fasterxml.jackson.databind.JsonNode src, String name)- Parameters:
src-name-- Returns:
- true only if the given field exists and is not set to null
-
parse
public static com.fasterxml.jackson.databind.node.ObjectNode parse(String contents)
-
parse
public static com.fasterxml.jackson.databind.node.ObjectNode parse(byte[] contents)
-
serialize
public static String serialize(com.fasterxml.jackson.databind.JsonNode node)
-
serializeHumanReadable
public static String serializeHumanReadable(com.fasterxml.jackson.databind.JsonNode node)
-
serialize2Bytes
public static byte[] serialize2Bytes(com.fasterxml.jackson.databind.JsonNode node)
-
toJsonNode
public static com.fasterxml.jackson.databind.JsonNode toJsonNode(Object value)
-
-