Introduce JsonProvider.
It will ensure that classes are using the correct Json instances in the unit tests.
This commit is contained in:
parent
fa8ddba1f5
commit
df48ed5a2d
21 changed files with 103 additions and 52 deletions
|
|
@ -32,6 +32,7 @@ dependencies {
|
|||
implementation(libs.androidx.recyclerview)
|
||||
implementation(libs.androidx.exifinterface)
|
||||
implementation(libs.androidx.datastore.preferences)
|
||||
implementation(libs.serialization.json)
|
||||
api(libs.androidx.browser)
|
||||
|
||||
testCommonDependencies(libs)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Copyright 2025 New Vector Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.libraries.androidutils.json
|
||||
|
||||
import dev.zacsweers.metro.AppScope
|
||||
import dev.zacsweers.metro.ContributesBinding
|
||||
import dev.zacsweers.metro.Inject
|
||||
import dev.zacsweers.metro.Provider
|
||||
import dev.zacsweers.metro.SingleIn
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
/**
|
||||
* Provides a Json instance configured to ignore unknown keys.
|
||||
*/
|
||||
interface JsonProvider : Provider<Json>
|
||||
|
||||
@ContributesBinding(AppScope::class)
|
||||
@SingleIn(AppScope::class)
|
||||
@Inject
|
||||
class DefaultJsonProvider : JsonProvider {
|
||||
private val json: Json by lazy { Json { ignoreUnknownKeys = true } }
|
||||
override fun invoke() = json
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue