Class GsonConverterFactory

java.lang.Object
retrofit2.Converter.Factory
retrofit2.converter.gson.GsonConverterFactory

public final class GsonConverterFactory
extends retrofit2.Converter.Factory
A converter which uses Gson for JSON.

Because Gson is so flexible in the types it supports, this converter assumes that it can handle all types. If you are mixing JSON serialization with something else (such as protocol buffers), you must add this instance last to allow the other converters a chance to see their types.

  • Method Summary

    Modifier and Type Method Description
    static GsonConverterFactory create()
    Create an instance using a default Gson instance for conversion.
    static GsonConverterFactory create​(com.google.gson.Gson gson)
    Create an instance using gson for conversion.
    retrofit2.Converter<?,​okhttp3.RequestBody> requestBodyConverter​(java.lang.reflect.Type type, java.lang.annotation.Annotation[] parameterAnnotations, java.lang.annotation.Annotation[] methodAnnotations, retrofit2.Retrofit retrofit)  
    retrofit2.Converter<okhttp3.ResponseBody,​?> responseBodyConverter​(java.lang.reflect.Type type, java.lang.annotation.Annotation[] annotations, retrofit2.Retrofit retrofit)  

    Methods inherited from class retrofit2.Converter.Factory

    getParameterUpperBound, getRawType, stringConverter

    Methods inherited from class java.lang.Object

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

    • create

      public static GsonConverterFactory create()
      Create an instance using a default Gson instance for conversion. Encoding to JSON and decoding from JSON (when no charset is specified by a header) will use UTF-8.
    • create

      public static GsonConverterFactory create​(com.google.gson.Gson gson)
      Create an instance using gson for conversion. Encoding to JSON and decoding from JSON (when no charset is specified by a header) will use UTF-8.
    • responseBodyConverter

      public retrofit2.Converter<okhttp3.ResponseBody,​?> responseBodyConverter​(java.lang.reflect.Type type, java.lang.annotation.Annotation[] annotations, retrofit2.Retrofit retrofit)
      Overrides:
      responseBodyConverter in class retrofit2.Converter.Factory
    • requestBodyConverter

      public retrofit2.Converter<?,​okhttp3.RequestBody> requestBodyConverter​(java.lang.reflect.Type type, java.lang.annotation.Annotation[] parameterAnnotations, java.lang.annotation.Annotation[] methodAnnotations, retrofit2.Retrofit retrofit)
      Overrides:
      requestBodyConverter in class retrofit2.Converter.Factory