public final class MoshiConverterFactory extends Converter.Factory
Because Moshi 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.
Any @JsonQualifier-annotated annotations on the parameter will be used
when looking up a request body converter and those on the method will be used when looking up a
response body converter.
| Modifier and Type | Method and Description |
|---|---|
MoshiConverterFactory |
asLenient()
Return a new factory which uses lenient adapters.
|
static MoshiConverterFactory |
create()
Create an instance using a default
Moshi instance for conversion. |
static MoshiConverterFactory |
create(com.squareup.moshi.Moshi moshi)
Create an instance using
moshi for conversion. |
MoshiConverterFactory |
failOnUnknown()
Return a new factory which uses
JsonAdapter.failOnUnknown() adapters. |
Converter<?,okhttp3.RequestBody> |
requestBodyConverter(Type type,
Annotation[] parameterAnnotations,
Annotation[] methodAnnotations,
Retrofit retrofit)
Returns a
Converter for converting type to an HTTP request body, or null if
type cannot be handled by this factory. |
Converter<okhttp3.ResponseBody,?> |
responseBodyConverter(Type type,
Annotation[] annotations,
Retrofit retrofit)
Returns a
Converter for converting an HTTP response body to type, or null if
type cannot be handled by this factory. |
MoshiConverterFactory |
withNullSerialization()
Return a new factory which includes null values into the serialized JSON.
|
getParameterUpperBound, getRawType, stringConverterpublic static MoshiConverterFactory create()
Moshi instance for conversion.public static MoshiConverterFactory create(com.squareup.moshi.Moshi moshi)
moshi for conversion.public MoshiConverterFactory asLenient()
public MoshiConverterFactory failOnUnknown()
JsonAdapter.failOnUnknown() adapters.public MoshiConverterFactory withNullSerialization()
public Converter<okhttp3.ResponseBody,?> responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit)
Converter.FactoryConverter for converting an HTTP response body to type, or null if
type cannot be handled by this factory. This is used to create converters for
response types such as SimpleResponse from a Call<SimpleResponse>
declaration.responseBodyConverter in class Converter.Factorypublic Converter<?,okhttp3.RequestBody> requestBodyConverter(Type type, Annotation[] parameterAnnotations, Annotation[] methodAnnotations, Retrofit retrofit)
Converter.FactoryConverter for converting type to an HTTP request body, or null if
type cannot be handled by this factory. This is used to create converters for types
specified by @Body, @Part, and @PartMap
values.requestBodyConverter in class Converter.FactoryCopyright © 2017 Square, Inc.. All rights reserved.