Class JSONCodec


  • public class JSONCodec
    extends java.lang.Object
    This class implements serialising/deserialising of Java objects from and to JSON strings.

    Multi-Threading

    Not thread-safe.
    Author:
    homac
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <T> T decodeObject​(java.io.InputStream inputStream, java.lang.Class<T> targetType)
      Decodes the given JSON string from input stream into a Java object of the given target type T.
      <T> T decodeObject​(java.io.InputStream inputStream, T targetObject)
      Decodes the given JSON string from input stream into the given target object of type T.
      <T> T decodeObject​(java.lang.String jsonString, java.lang.Class<T> targetType)
      Decodes the given JSON string into a Java object of the given target type T.
      <T> T decodeObject​(java.lang.String jsonString, T javaObject)
      Decodes the given jsonString into the given target javaObject of type T.
      java.lang.String encodeObject​(java.lang.Object o)
      Encodes given Java object into a JSON string, which is returned.
      void encodeObject​(java.lang.Object javaObject, java.io.OutputStream out)
      Encodes given Java object into a JSON string, wirtten to out.
      • Methods inherited from class java.lang.Object

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

      • JSONCodec

        public JSONCodec()
        Constructor using the default configuration.
    • Method Detail

      • decodeObject

        public <T> T decodeObject​(java.lang.String jsonString,
                                  T javaObject)
                           throws JSONException
        Decodes the given jsonString into the given target javaObject of type T.
        Throws:
        JSONException
      • decodeObject

        public <T> T decodeObject​(java.io.InputStream inputStream,
                                  T targetObject)
                           throws JSONException
        Decodes the given JSON string from input stream into the given target object of type T.
        Throws:
        JSONException
      • decodeObject

        public <T> T decodeObject​(java.io.InputStream inputStream,
                                  java.lang.Class<T> targetType)
                           throws JSONException
        Decodes the given JSON string from input stream into a Java object of the given target type T.
        Throws:
        JSONException
      • decodeObject

        public <T> T decodeObject​(java.lang.String jsonString,
                                  java.lang.Class<T> targetType)
                           throws JSONException
        Decodes the given JSON string into a Java object of the given target type T.
        Throws:
        JSONException
      • encodeObject

        public java.lang.String encodeObject​(java.lang.Object o)
                                      throws JSONException
        Encodes given Java object into a JSON string, which is returned.
        Throws:
        JSONException
      • encodeObject

        public void encodeObject​(java.lang.Object javaObject,
                                 java.io.OutputStream out)
                          throws JSONException
        Encodes given Java object into a JSON string, wirtten to out.
        Throws:
        JSONException