Tinder / Scarlet

A Retrofit inspired WebSocket client for Kotlin, Java, and Android
Other
3.23k stars 237 forks source link

Converting from JSON to Object doesn't take in account fields quantity. #195

Open AndreuZaitsev opened 2 years ago

AndreuZaitsev commented 2 years ago
@JsonClass(generateAdapter = true)
data class Dto1(
    @Json(name = "code") val code: String,
    @Json(name = "status") val status: Int,
)

@JsonClass(generateAdapter = true)
data class Dto2(
    @Json(name = "status") val status: Int,
    @Json(name = "token") val token: String?,
)

@JsonClass(generateAdapter = true)
data class Dto3(
    @Json(name = "code") val code: String,
    @Json(name = "status") val status: Int,
    @Json(name = "token") val token: String?,
    @Json(name = "user") val user: UserResponse
)

Whenever Dto3 is received, all these DTOsare converted and emitted to the appropriate flows.

There are cases when you need to observe several sources, but due to that issue, you should apply redundant validators on each source.

P.S. I guess this is a problem of Moshi.

rubinbasha commented 2 years ago

this problem also happens with Gson

boronov commented 1 year ago

+