Skip to content

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

Description

@ArcherEmiya05

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions