|
|
@ -10,7 +10,6 @@ import okhttp3.RequestBody; |
|
|
|
import okhttp3.ResponseBody; |
|
|
|
import okhttp3.ResponseBody; |
|
|
|
import retrofit2.Converter; |
|
|
|
import retrofit2.Converter; |
|
|
|
import retrofit2.Retrofit; |
|
|
|
import retrofit2.Retrofit; |
|
|
|
import retrofit2.converter.gson.GsonConverterFactory; |
|
|
|
|
|
|
|
import timber.log.Timber; |
|
|
|
import timber.log.Timber; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -21,9 +20,9 @@ import timber.log.Timber; |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class ErrorJsonLenientConverterFactory extends Converter.Factory { |
|
|
|
public class ErrorJsonLenientConverterFactory extends Converter.Factory { |
|
|
|
|
|
|
|
|
|
|
|
private final GsonConverterFactory mGsonConverterFactory; |
|
|
|
private final Converter.Factory mGsonConverterFactory; |
|
|
|
|
|
|
|
|
|
|
|
public ErrorJsonLenientConverterFactory(GsonConverterFactory gsonConverterFactory) { |
|
|
|
public ErrorJsonLenientConverterFactory(Converter.Factory gsonConverterFactory) { |
|
|
|
mGsonConverterFactory = gsonConverterFactory; |
|
|
|
mGsonConverterFactory = gsonConverterFactory; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -32,22 +31,23 @@ public class ErrorJsonLenientConverterFactory extends Converter.Factory { |
|
|
|
Annotation[] parameterAnnotations, |
|
|
|
Annotation[] parameterAnnotations, |
|
|
|
Annotation[] methodAnnotations, |
|
|
|
Annotation[] methodAnnotations, |
|
|
|
Retrofit retrofit) { |
|
|
|
Retrofit retrofit) { |
|
|
|
|
|
|
|
|
|
|
|
return mGsonConverterFactory.requestBodyConverter(type, parameterAnnotations, methodAnnotations, retrofit); |
|
|
|
return mGsonConverterFactory.requestBodyConverter(type, parameterAnnotations, methodAnnotations, retrofit); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Converter<ResponseBody, ?> responseBodyConverter(Type type, |
|
|
|
public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) { |
|
|
|
Annotation[] annotations, |
|
|
|
|
|
|
|
Retrofit retrofit) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final Converter<ResponseBody, ?> delegateConverter = mGsonConverterFactory.responseBodyConverter(type, annotations, retrofit); |
|
|
|
final Converter<ResponseBody, ?> delegateConverter = mGsonConverterFactory.responseBodyConverter(type, annotations, retrofit); |
|
|
|
|
|
|
|
assert delegateConverter != null; |
|
|
|
|
|
|
|
|
|
|
|
return (Converter<ResponseBody, Object>) value -> { |
|
|
|
return (Converter<ResponseBody, Object>) value -> { |
|
|
|
try { |
|
|
|
try { |
|
|
|
return delegateConverter.convert(value); |
|
|
|
return delegateConverter.convert(value); |
|
|
|
} catch (Exception e/*防止闪退:JsonSyntaxException、IOException or MalformedJsonException*/) { |
|
|
|
} catch (Exception e/*防止闪退:JsonSyntaxException、IOException or MalformedJsonException*/) { |
|
|
|
Timber.e(e, "Json covert error -->error "); |
|
|
|
Timber.e(e, "Json covert error -->error "); |
|
|
|
return NetContext.get().netProvider().errorDataAdapter().createErrorDataStub(type, annotations, retrofit, value);//服务器数据格式错误
|
|
|
|
//服务器数据格式错误
|
|
|
|
|
|
|
|
return NetContext.get().netProvider().errorDataAdapter().createErrorDataStub(type, annotations, retrofit, value); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|