Class LfsGson


  • public class LfsGson
    extends java.lang.Object
    Wrapper for Gson used by LFS servlets.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      (package private) static class  LfsGson.Error
      Wrapper class only used for serialization of error messages.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static com.google.gson.Gson gson  
    • Constructor Summary

      Constructors 
      Constructor Description
      LfsGson()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> T fromJson​(java.io.Reader json, java.lang.Class<T> classOfT)
      Deserializes the Json read from the specified reader into an object of the specified type.
      static void toJson​(java.lang.Object src, java.lang.Appendable writer)
      Serializes the specified object into its equivalent Json representation.
      • Methods inherited from class java.lang.Object

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

      • gson

        private static final com.google.gson.Gson gson
    • Constructor Detail

      • LfsGson

        public LfsGson()
    • Method Detail

      • toJson

        public static void toJson​(java.lang.Object src,
                                  java.lang.Appendable writer)
                           throws com.google.gson.JsonIOException
        Serializes the specified object into its equivalent Json representation.
        Parameters:
        src - the object for which Json representation is to be created. If this is a String, it is wrapped in an instance of LfsGson.Error.
        writer - Writer to which the Json representation needs to be written
        Throws:
        com.google.gson.JsonIOException - if there was a problem writing to the writer
        See Also:
        Gson.toJson(Object, Appendable)
      • fromJson

        public static <T> T fromJson​(java.io.Reader json,
                                     java.lang.Class<T> classOfT)
                              throws com.google.gson.JsonSyntaxException,
                                     com.google.gson.JsonIOException
        Deserializes the Json read from the specified reader into an object of the specified type.
        Type Parameters:
        T - a T object.
        Parameters:
        json - reader producing json from which the object is to be deserialized
        classOfT - specified type to deserialize
        Returns:
        an Object of type T
        Throws:
        com.google.gson.JsonIOException - if there was a problem reading from the Reader
        com.google.gson.JsonSyntaxException - if json is not a valid representation for an object of type
        See Also:
        Gson.fromJson(Reader, java.lang.reflect.Type)