Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
AndreuZaitsev opened this issue Oct 27, 2021 · 2 comments

Comments

@AndreuZaitsev
Copy link

AndreuZaitsev commented Oct 27, 2021

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

@rubinbasha
Copy link

this problem also happens with Gson

@boronov
Copy link

boronov commented Jul 10, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants