AriesHoo / FastLib

一个Android项目级快速开发框架,节约大部分写常用功能时间以实现更多项目业务功能及体验上的优化。使用说明见wiki
https://github.com/AriesHoo/FastLib/wiki
Apache License 2.0
492 stars 95 forks source link

无法创建转换器 Unable to create converter for class #53

Closed iSally closed 4 years ago

iSally commented 4 years ago

Unable to create converter for class

可是我确实看到作者在FastRetrofit中添加了转换器

private FastRetrofit() {
    sClientBuilder = new OkHttpClient.Builder();
    sClientBuilder.addInterceptor(mHeaderInterceptor);
    sRetrofitBuilder = new Retrofit.Builder()
            .addConverterFactory(GsonConverterFactory.create())
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create());
    setTimeout(mDelayTime);
    FastMultiUrl.getInstance().with(sClientBuilder);
}

搞了一下午,我头都大了

AriesHoo commented 4 years ago

你自己创建转换器代码咋写的?

iSally commented 4 years ago

public class FastJsonResponseBodyConverter implements Converter<ResponseBody, String> {

FastJsonResponseBodyConverter() {
}

@Override
public String convert(@NonNull ResponseBody value) throws IOException {

    String string = value.string().replace(" ", "");
    String response = string.substring(1, string.length() - 1).replace("\\\"", "\"");
    response = response.replace("\\\\","\\");
    boolean isHead = true;
    if (BuildConfig.DEBUG) {
        if (response.length() > 3500) {
            for (int i = 0; i < response.length(); i += 3500) {
                if (i + 3500 < response.length()) {
                    if (isHead) {
                        Log.i("FastJsonResponseBody", "<---part-" + (i / 3500 + 1) + "--->" + response.substring(i, i + 3500));
                        isHead = false;
                    } else {
                        Log.i("FastJsonResponseBody", "<---part-" + (i / 3500 + 1) + "--->" + response.substring(i, i + 3500));
                    }
                } else {
                    Log.i("FastJsonResponseBody", "<---part-" + (i / 3500 + 1) + "--->" + response.substring(i, response.length()));
                }
            }
        } else {
            Log.i("FastJsonResponseBody", "<---data--->" + response);
        }
    }

    return response;
}

}


这个是我自己写的转换器,但是我还没add,我也纳闷为啥为啥无法创建转换器

iSally commented 4 years ago

我添加了自己的转换器,他也报错,