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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic 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 booleanstatic com.fasterxml.jackson.databind.node.ObjectNodeparse(byte[] contents) static com.fasterxml.jackson.databind.node.ObjectNodestatic <T> Tstatic <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)
-
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
-