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

Adapter generation fails when you have different models that are nested, but have the same name #1143

Open
ColtonIdle opened this issue May 21, 2020 · 4 comments

Comments

@ColtonIdle
Copy link

ColtonIdle commented May 21, 2020

My backend has a weird model defined. I can't really do anything about it. Moshi codegen breaks though.

@JsonClass(generateAdapter = true)
data class UserWrapper(
    var id: Int? = 0,
    var users: List<User?>? = listOf()
) {
    @JsonClass(generateAdapter = true)
    data class User(
        var partnerUser: PartnerUser? = PartnerUser()
    ) {
        @JsonClass(generateAdapter = true)
        data class PartnerUser(
            var isPartner: Boolean? = false,
            var nestedUser: User? = User()
        ) {
            @JsonClass(generateAdapter = true)
            data class User(
                var email: String? = ""
            )
        }
    }
}

Switching to moshi reflect works fine though.

EDIT: I couldn't find a stacktrace because it complains about Dagger, and no matter how long I hunted through the stacktrace output I couldn't find anything related to moshi. Once I remove these annotations everything works.

@vivekpanchal
Copy link

I am having the same issue did you find any solution to this?

@swankjesse
Copy link
Member

Likely a KotlinPoet issue.

@ZacSweers
Copy link
Collaborator

We built some handling for this in JavaPoet, seems like it's worth adding APIs for in KotlinPoet too. @ColtonIdle feel free to file an issue there. You can work around this by just not nesting your classes like that for now.

@Ryubal
Copy link

Ryubal commented Jan 29, 2022

Any updates on this? I just came upon this issue.

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

No branches or pull requests

5 participants