All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.fasterxml.jackson.jr.retrofit2.JacksonJrConverter Maven / Gradle / Ivy

The newest version!
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 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