Class JsonUtils


  • public class JsonUtils
    extends java.lang.Object
    JSON utilities.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> T fromJson​(java.lang.String source, java.lang.Class<T> valueType)
      Converts a JSON string to an object.
      static <T> T fromJson​(java.lang.String source, java.lang.Class<T> valueType, java.util.Map<java.lang.String,​java.lang.String> parameters)
      Converts a JSON string to an object, using variable substitution.
      static <T> T loadJson​(java.lang.String resource, java.lang.Class<T> valueType)
      Loads a JSON string from a file and converts it to an object.
      static <T> T loadJson​(java.lang.String resource, java.lang.Class<T> valueType, java.util.Map<java.lang.String,​java.lang.String> parameters)
      Loads a JSON string from a file and converts it to an object, using variable substitution.
      static java.lang.String toJson​(java.lang.Object source)
      Converts an object to a JSON string.
      • Methods inherited from class java.lang.Object

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

      • toJson

        public static final java.lang.String toJson​(java.lang.Object source)
        Converts an object to a JSON string.
        Parameters:
        source - - the source object
        Returns:
        a JSON string
      • fromJson

        public static final <T> T fromJson​(java.lang.String source,
                                           java.lang.Class<T> valueType)
        Converts a JSON string to an object.
        Parameters:
        source - - the source JSON string
        valueType - - the value type of the target object
        Returns:
        an object
      • fromJson

        public static final <T> T fromJson​(java.lang.String source,
                                           java.lang.Class<T> valueType,
                                           java.util.Map<java.lang.String,​java.lang.String> parameters)
        Converts a JSON string to an object, using variable substitution.
        Parameters:
        source - - the source JSON string
        valueType - - the value type of the target object
        parameters - - the parameters used for variable substitution
        Returns:
        an object
      • loadJson

        public static final <T> T loadJson​(java.lang.String resource,
                                           java.lang.Class<T> valueType)
        Loads a JSON string from a file and converts it to an object.
        Parameters:
        resource - - the resource that contains the JSON string
        valueType - - the value type of the target object
        Returns:
        an object
      • loadJson

        public static final <T> T loadJson​(java.lang.String resource,
                                           java.lang.Class<T> valueType,
                                           java.util.Map<java.lang.String,​java.lang.String> parameters)
        Loads a JSON string from a file and converts it to an object, using variable substitution.
        Parameters:
        resource - - the resource that contains the JSON string
        valueType - - the value type of the target object
        parameters - - the parameters used for variable substitution
        Returns:
        an object