Class JsonUtil


  • public class JsonUtil
    extends Object
    Simplifies JSON parsing a little bit
    Author:
    K. Benedyczak
    • Constructor Detail

      • JsonUtil

        public JsonUtil()
    • Method Detail

      • 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)
      • parse

        public static <T> T parse​(String contents,
                                  Class<T> clazz)
      • parseToList

        public static <T> List<T> parseToList​(String contents,
                                              Class<T> clazz)
      • toJsonString

        public static String toJsonString​(Object value)
      • toJsonNode

        public static com.fasterxml.jackson.databind.JsonNode toJsonNode​(Object value)