Created
November 18, 2015 04:54
-
-
Save GulajavaMinistudio/f0d0a62d8d5d08a3d6c7 to your computer and use it in GitHub Desktop.
JacksonJrConverter class for Converter.Factory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package gk.retrofittest; | |
import com.squareup.okhttp.RequestBody; | |
import com.squareup.okhttp.ResponseBody; | |
import java.lang.annotation.Annotation; | |
import java.lang.reflect.Type; | |
import retrofit.Converter; | |
/** | |
* Created by Gulajava Ministudio on 11/13/15. | |
*/ | |
public class JacksonJrConverter<T> extends Converter.Factory { | |
private Class<T> clazz; | |
public JacksonJrConverter(Class<T> tClass) { | |
super(); | |
this.clazz = tClass; | |
} | |
@Override | |
public Converter<ResponseBody, ?> fromResponseBody(Type type, Annotation[] annotations) { | |
super.fromResponseBody(type, annotations); | |
//if same as class type return as class, otherwise, return as list | |
if (clazz == type) { | |
return new JacksonJrResponseConverter<>(clazz); | |
} else { | |
return new JacksonJrResponseArrayConverter<>(clazz); | |
} | |
} | |
@Override | |
public Converter<?, RequestBody> toRequestBody(Type type, Annotation[] annotations) { | |
super.toRequestBody(type, annotations); | |
return new JacksonJrRequestBodyConverter<>(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment