com.alibaba.fastjson2.support.retrofit.Retrofit2ConverterFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fastjson2-extension Show documentation
Show all versions of fastjson2-extension Show documentation
Fastjson is a JSON processor (JSON parser + JSON generator) written in Java
The newest version!
package com.alibaba.fastjson2.support.retrofit;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONB;
import com.alibaba.fastjson2.support.config.FastJsonConfig;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.Converter;
import retrofit2.Retrofit;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
/**
* Fastjson for Retrofit Converter Json Factory.
*
* @author ligboy, wenshao
* @author Victor.Zxy
* @see Converter.Factory
* @since 2.0.2
*/
public class Retrofit2ConverterFactory
extends Converter.Factory {
private static final MediaType MEDIA_TYPE = MediaType.parse("application/json; charset=UTF-8");
private FastJsonConfig config;
public Retrofit2ConverterFactory() {
this.config = new FastJsonConfig();
}
public Retrofit2ConverterFactory(FastJsonConfig fastJsonConfig) {
this.config = fastJsonConfig;
}
public static Retrofit2ConverterFactory create() {
return create(new FastJsonConfig());
}
public static Retrofit2ConverterFactory create(FastJsonConfig fastJsonConfig) {
if (fastJsonConfig == null) {
throw new NullPointerException("fastJsonConfig == null");
}
return new Retrofit2ConverterFactory(fastJsonConfig);
}
@Override
public Converter responseBodyConverter(
Type type,
Annotation[] annotations,
Retrofit retrofit
) {
return new ResponseBodyConverter