Class JsonHelper


  • public final class JsonHelper
    extends Object
    This class is an helper to work with JSON.
    Since:
    1.0.0
    Author:
    Jerome Leleu
    • Method Detail

      • getFirstNode

        public static com.fasterxml.jackson.databind.JsonNode getFirstNode​(String text)
        Return the first node of a JSON response.
        Parameters:
        text - JSON text
        Returns:
        the first node of the JSON response or null if exception is thrown
      • getFirstNode

        public static com.fasterxml.jackson.databind.JsonNode getFirstNode​(String text,
                                                                           String path)
        Return the first node of a JSON response.
        Parameters:
        text - JSON text
        path - path to find the first node
        Returns:
        the first node of the JSON response or null if exception is thrown
      • getElement

        public static Object getElement​(com.fasterxml.jackson.databind.JsonNode json,
                                        String name)
        Return the field with name in JSON as a string, a boolean, a number or a node.
        Parameters:
        json - json
        name - node name
        Returns:
        the field
      • toJSONString

        public static String toJSONString​(Object obj)
        Returns the JSON string for the object.
        Parameters:
        obj - the object
        Returns:
        the JSON string
      • getMapper

        public static com.fasterxml.jackson.databind.ObjectMapper getMapper()