com.fasterxml.jackson.jr.retrofit2.JacksonJrConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jackson-jr-retrofit2 Show documentation
Show all versions of jackson-jr-retrofit2 Show documentation
Basic provider implementation for Retrofit 2 library
package com.fasterxml.jackson.jr.retrofit2;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import com.fasterxml.jackson.jr.ob.JSON;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.Converter;
import retrofit2.Retrofit;
public class JacksonJrConverter extends Converter.Factory
{
protected final JSON _jr;
protected final Class _type;
public JacksonJrConverter(Class tClass) {
this(JSON.std, tClass);
}
public JacksonJrConverter(JSON jr, Class t) {
super();
_jr = jr;
_type = t;
}
@Override
public Converter responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit)
{
super.responseBodyConverter(type, annotations, retrofit);
//if same as class type return as class, otherwise, return as list
if (_type == type) {
return new JacksonJrResponseConverter(_jr, _type);
}
return new JacksonJrResponseArrayConverter(_jr, _type);
}
@Override
public Converter, RequestBody> requestBodyConverter(Type type, Annotation[] parameterAnnotations, Annotation[] methodAnnotations, Retrofit retrofit)
{
super.requestBodyConverter(type, parameterAnnotations, methodAnnotations, retrofit);
return new JacksonJrRequestBodyConverter(_jr);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy