Scarlet icon indicating copy to clipboard operation
Scarlet copied to clipboard

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

Open AndreuZaitsev opened this issue 4 years ago • 2 comments

@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 DTOs are 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.

AndreuZaitsev avatar Oct 27 '21 11:10 AndreuZaitsev

this problem also happens with Gson

rubinbasha avatar Dec 09 '21 09:12 rubinbasha

boronov avatar Jul 10 '23 08:07 boronov