square/moshi

Type mismatch: inferred type is Buffer but BufferedSink! was expected

ArcherEmiya05 opened this issue · 0 comments

Moshi Version: 1.15.0
Moshi Converter Version: 2.9.0
AGP: 8.1.3
Android Studio: Android Studio Giraffe | 2022.3.1 Patch 3

Code:

override fun <K, V> toJsonString(keyType: Type, valueType: Type, value: Map<K, V>): String? {

        val jsonAdapter: JsonAdapter<Map<K, V>> = moshi.adapter(
            Types.newParameterizedType(
                Map::class.java,
                keyType,
                valueType
            ))

        val buffer = Buffer()
        val jsonWriter: JsonWriter = JsonWriter.of(buffer)
        jsonWriter.serializeNulls = true
        jsonAdapter.toJson(jsonWriter, value)

        return try {
            buffer.readUtf8()
        }
        catch (e: Exception) {
            e.printStackTrace()
            null
        }

    }

The line JsonWriter.of(buffer) is having two error, but still compile and run.

Cannot access class 'okio.BufferedSink'. Check your module classpath for missing or conflicting dependencies
Type mismatch: inferred type is Buffer but BufferedSink! was expected