mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-14 10:37:05 +05:30
all: allow unknown keys in responses
This commit is contained in:
parent
b5c2dc9aaf
commit
6eb3acff78
3 changed files with 12 additions and 3 deletions
|
@ -38,12 +38,13 @@ object ApiModule {
|
|||
@Provides
|
||||
fun provideRetrofit(
|
||||
client: Lazy<OkHttpClient>,
|
||||
json: Lazy<Json>,
|
||||
): Retrofit {
|
||||
val contentType = "application/json".toMediaType()
|
||||
return Retrofit.Builder()
|
||||
.client(client.get())
|
||||
.baseUrl(LobstersApi.BASE_URL)
|
||||
.addConverterFactory(Json.asConverterFactory(contentType))
|
||||
.addConverterFactory(json.get().asConverterFactory(contentType))
|
||||
.build()
|
||||
}
|
||||
|
||||
|
@ -51,4 +52,9 @@ object ApiModule {
|
|||
fun provideApi(retrofit: Retrofit): LobstersApi {
|
||||
return retrofit.create()
|
||||
}
|
||||
|
||||
@Provides
|
||||
fun provideJsonSerializer(): Json {
|
||||
return Json { ignoreUnknownKeys = true }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,11 +27,12 @@ class LobstersApiTest {
|
|||
private val contentType = "application/json".toMediaType()
|
||||
private val webServer = MockWebServer()
|
||||
private val okHttp = OkHttpClient.Builder().build()
|
||||
private val json = Json { ignoreUnknownKeys = true }
|
||||
private val retrofit =
|
||||
Retrofit.Builder()
|
||||
.client(okHttp)
|
||||
.baseUrl("http://localhost:8080/")
|
||||
.addConverterFactory(Json.asConverterFactory(contentType))
|
||||
.addConverterFactory(json.asConverterFactory(contentType))
|
||||
.build()
|
||||
private val apiClient = retrofit.create<LobstersApi>()
|
||||
|
||||
|
|
|
@ -9,6 +9,8 @@ import retrofit2.create
|
|||
|
||||
@OptIn(ExperimentalSerializationApi::class)
|
||||
class Api {
|
||||
private val json = Json { ignoreUnknownKeys = true }
|
||||
|
||||
private fun getOkHttpClient(): OkHttpClient {
|
||||
return OkHttpClient.Builder()
|
||||
.addNetworkInterceptor { chain ->
|
||||
|
@ -26,7 +28,7 @@ class Api {
|
|||
return Retrofit.Builder()
|
||||
.client(okHttpClient)
|
||||
.baseUrl(LobstersApi.BASE_URL)
|
||||
.addConverterFactory(Json.asConverterFactory(contentType))
|
||||
.addConverterFactory(json.asConverterFactory(contentType))
|
||||
.build()
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue