Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

Does retrofit2 + kotlinx-serialization support returning MutableMap<String, String?> #87

Open
zzyyppqq opened this issue Aug 29, 2023 · 0 comments

Comments

@zzyyppqq
Copy link

Does retrofit2 + kotlinx-serialization support returning MutableMap<String, String?>

After testing, retrofit2 + converter-gson is supported

Unexpected JSON token at offset 49: Unexpected 'null' value instead of string literal at path: $['language']
JSON input: {"name":"kotlinx.serialization", "language": null}
kotlinx.serialization.json.internal.JsonDecodingException: Unexpected JSON token at offset 49: Unexpected 'null' value instead of string literal at path: $['language']
JSON input: {"name":"kotlinx.serialization", "language": null}

interface ApiService {
    @GET("my/test")
    suspend fun test(): Response<MutableMap<String, String?>>
}

@Serializable
data class Response<T>(
    var code: Int = 0,
    var msg: String = "",
    var serverTime: Long = 0,
    var data: T? = null,
)

response json:

{
  "data": {
    "name": "kotlinx.serialization",
    "language": null
  },
  "code": 1,
  "msg": ""
}
@zzyyppqq zzyyppqq changed the title kotlinx.serialization.json.internal.JsonDecodingException Does retrofit2 + kotlinx-serialization support returning MutableMap<String, String?> Aug 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant