Class JsonParser


  • public class JsonParser
    extends java.lang.Object
    Contains static methods to parse and to serialize objects.
    See Also:
    TypeInfo, TypeClassInfo, TypeParser
    • Constructor Summary

      Constructors 
      Constructor Description
      JsonParser()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> T fromJson​(java.lang.String json, java.lang.Class<T> classType)
      Parses the JSON string as the instance of classType.
      static <T> T fromJsonObject​(org.json.JSONObject json, java.lang.Class<T> classType)
      Parses the JSONObject as the instance of classType.
      static java.lang.String toJson​(java.lang.Object object)
      Serialize object to a JSON string.
      static org.json.JSONObject toJsonObject​(java.lang.Object object)
      Serialize object to a JSONObject.
      • Methods inherited from class java.lang.Object

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

      • JsonParser

        public JsonParser()
    • Method Detail

      • fromJson

        @Nullable
        public static <T> T fromJson​(@NonNull
                                     java.lang.String json,
                                     @NonNull
                                     java.lang.Class<T> classType)
        Parses the JSON string as the instance of classType.

        Never throws.

        Type Parameters:
        T - target type
        Parameters:
        json - json
        classType - class
        Returns:
        new instance or null in case of errors
      • fromJsonObject

        @Nullable
        public static <T> T fromJsonObject​(@NonNull
                                           org.json.JSONObject json,
                                           @NonNull
                                           java.lang.Class<T> classType)
        Parses the JSONObject as the instance of classType.

        Never throws.

        Type Parameters:
        T - target type
        Parameters:
        json - json
        classType - class
        Returns:
        new instance or null in case of errors
      • toJson

        @NonNull
        public static java.lang.String toJson​(@Nullable
                                              java.lang.Object object)
        Serialize object to a JSON string.
        Parameters:
        object - object
        Returns:
        single-line string
      • toJsonObject

        @Nullable
        public static org.json.JSONObject toJsonObject​(@Nullable
                                                       java.lang.Object object)
        Serialize object to a JSONObject.
        Parameters:
        object - object
        Returns:
        new instance or null