类 GsonHttpMessageConverter

所有已实现的接口:
GenericHttpMessageConverter<Object>, HttpMessageConverter<Object>

public class GsonHttpMessageConverter extends AbstractJsonHttpMessageConverter
Implementation of HttpMessageConverter that can read and write JSON using the Google Gson library.

This converter can be used to bind to typed beans or untyped HashMaps. By default, it supports application/json and application/*+json with UTF-8 character set.

Tested against Gson 2.8; compatible with Gson 2.0 and higher.

从以下版本开始:
4.0
作者:
Roy Clarkson, Juergen Hoeller
另请参阅:
  • 字段详细资料

    • gson

      private com.google.gson.Gson gson
  • 构造器详细资料

    • GsonHttpMessageConverter

      public GsonHttpMessageConverter()
      Construct a new GsonHttpMessageConverter with default configuration.
    • GsonHttpMessageConverter

      public GsonHttpMessageConverter(com.google.gson.Gson gson)
      Construct a new GsonHttpMessageConverter with the given delegate.
      参数:
      gson - the Gson instance to use
  • 方法详细资料

    • setGson

      public void setGson(com.google.gson.Gson gson)
      Set the Gson instance to use. If not set, a default Gson instance will be used.

      Setting a custom-configured Gson is one way to take further control of the JSON serialization process.

      另请参阅:
    • getGson

      public com.google.gson.Gson getGson()
      Return the configured Gson instance for this converter.
    • readInternal

      protected Object readInternal(Type resolvedType, Reader reader) throws Exception
      从类复制的说明: AbstractJsonHttpMessageConverter
      Template method that reads the JSON-bound object from the given Reader.
      指定者:
      readInternal 在类中 AbstractJsonHttpMessageConverter
      参数:
      resolvedType - the resolved generic type
      reader - the Reader to use
      返回:
      the JSON-bound object
      抛出:
      Exception - in case of read/parse failures
    • writeInternal

      protected void writeInternal(Object object, @Nullable Type type, Writer writer) throws Exception
      从类复制的说明: AbstractJsonHttpMessageConverter
      Template method that writes the JSON-bound object to the given Writer.
      指定者:
      writeInternal 在类中 AbstractJsonHttpMessageConverter
      参数:
      object - the object to write to the output message
      type - the type of object to write (may be null)
      writer - the Writer to use
      抛出:
      Exception - in case of write failures