Class JsonHelper


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

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.Object getElement​(com.fasterxml.jackson.databind.JsonNode json, java.lang.String name)
      Return the field with name in JSON as a string, a boolean, a number or a node.
      static com.fasterxml.jackson.databind.JsonNode getFirstNode​(java.lang.String text)
      Return the first node of a JSON response.
      static com.fasterxml.jackson.databind.JsonNode getFirstNode​(java.lang.String text, java.lang.String path)
      Return the first node of a JSON response.
      static com.fasterxml.jackson.databind.ObjectMapper getMapper()  
      static java.lang.String toJSONString​(java.lang.Object obj)
      Returns the JSON string for the object.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getFirstNode

        public static com.fasterxml.jackson.databind.JsonNode getFirstNode​(java.lang.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​(java.lang.String text,
                                                                           java.lang.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 java.lang.Object getElement​(com.fasterxml.jackson.databind.JsonNode json,
                                                  java.lang.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 java.lang.String toJSONString​(java.lang.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()