Tag: gson retrofit2

Android Kotlin Dagger2提供了gson:指定为非null的参数为null

我想提供一个单一的gson实例,所以我提供它在我的NetworkModule,当我创建改造api,gson是非null,但是当我在改造类中使用gson实例,它是空的.. @Module class NetworkModule { @Provides @Singleton fun provideGson(): Gson { return Gson() } @Provides @Singleton fun provideMyEnterpriseApi(gson: Gson): MyEnterpriseApi { //HERE GSON IS NOT NULL return RetrofitMyEnterpriseApi(BuildConfig.API_MYENTERPRISE_URL, BuildConfig.API_MYENTERPRISE_CONNECTION_TIMEOUT, BuildConfig.API_MYENTERPRISE_READ_TIMEOUT, gson) } } 我的翻新API类: class RetrofitMyEnterpriseApi(baseUrl: String, connectTimeout: Long, readTimeout: Long, private val gson: Gson) : RetrofitApi(baseUrl, connectTimeout, readTimeout, RetrofitMyEnterpriseCalls::class.java) { override fun buildRetrofit(baseUrl: String, […]

如何在Retrofit 2中打印漂亮的照片?

我有我的改造设置HttpLoggingInterceptor像这样: Gson gson = new GsonBuilder() .setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ") .setPrettyPrinting() // Pretty print .create(); HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(interceptor) .build(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(BASE_URL) .addConverterFactory(GsonConverterFactory.create(gson)) .client(client) .build(); 在我的Gson实例上,我做了setPrettyPrinting ,我仍然得到紧凑的JSON输出。 这是我的图书馆。 compile 'com.google.code.gson:gson:2.5' compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta4' compile 'com.squareup.okhttp3:logging-interceptor:3.0.1' compile 'com.squareup.retrofit2:retrofit:2.0.0-beta4' compile 'com.squareup.okhttp3:okhttp:3.0.1' 如何使用Retrofit 2实现漂亮的打印? 谢谢。 编辑:更新我的图书馆,仍然没有工作