public class GsonConverter extends java.lang.Object implements Converter
Converter
which uses GSON for serialization and deserialization of entities.Constructor and Description |
---|
GsonConverter(com.google.gson.Gson gson)
Create an instance using the supplied
Gson object for conversion. |
GsonConverter(com.google.gson.Gson gson,
java.lang.String encoding)
Create an instance using the supplied
Gson object for conversion. |
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
fromBody(TypedInput body,
java.lang.reflect.Type type)
Convert an HTTP response body to a concrete object of the specified type.
|
TypedOutput |
toBody(java.lang.Object object)
Convert and object to an appropriate representation for HTTP transport.
|
public GsonConverter(com.google.gson.Gson gson)
Gson
object for conversion. Encoding to JSON and
decoding from JSON (when no charset is specified by a header) will use UTF-8.public GsonConverter(com.google.gson.Gson gson, java.lang.String encoding)
Gson
object for conversion. Encoding to JSON and
decoding from JSON (when no charset is specified by a header) will use the specified encoding.public java.lang.Object fromBody(TypedInput body, java.lang.reflect.Type type) throws ConversionException
Converter
fromBody
in interface Converter
body
- HTTP response body.type
- Target object type.type
which will be cast by the caller.ConversionException
- if conversion was unable to complete. This will trigger a call to
Callback.failure(retrofit.RetrofitError)
or throw a
RetrofitError
. The exception message should report all necessary information
about its cause as the response body will be set to null
.public TypedOutput toBody(java.lang.Object object)
Converter
Copyright © 2014 Square, Inc.. All Rights Reserved.