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

Add support for moshi-kotlin-codegen #62

Closed
cortinico opened this issue Aug 9, 2019 · 2 comments · Fixed by #82
Closed

Add support for moshi-kotlin-codegen #62

cortinico opened this issue Aug 9, 2019 · 2 comments · Fixed by #82
Assignees
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@cortinico
Copy link
Collaborator

We're currently generating code that relies on moshi-kotlin:

private val moshi = Moshi.Builder()
.add(XNullableAdapterFactory())
.add(KotlinJsonAdapterFactory())
.add(TypesAdapterFactory())
.build()

This has the side effect of pulling in the kotlin-reflect dependency that is a pretty big jar.

We should consider moving over to moshi-kotlin-codegen.

Ideally we just need to generate the @JsonClass annotation for our data classes and make sure we provide proper proguard rules for it.

@cortinico cortinico added enhancement New feature or request help wanted Extra attention is needed labels Aug 9, 2019
@filipemp filipemp self-assigned this Sep 17, 2019
@filipemp
Copy link
Contributor

filipemp commented Sep 17, 2019

[BLOCKED] moshi-kotlin-codegen generates code that doesn't compile for ReservedKeywords.kt
It looks like this

override fun toJson(writer: JsonWriter, value: ReservedKeywords?) {
        if (value == null) {
            throw NullPointerException("value was null! Wrap in .nullSafe() to write nullable values.")
        }
        writer.beginObject()
        writer.name("class")
        nullableStringAdapter.toJson(writer, value.class)
        writer.name("for")
        nullableStringAdapter.toJson(writer, value.for)
        writer.name("operator")
        nullableStringAdapter.toJson(writer, value.operator)
        writer.name("val")
        nullableStringAdapter.toJson(writer, value.val)
        writer.name("var")
        nullableStringAdapter.toJson(writer, value.var)
        writer.name("when")
        nullableStringAdapter.toJson(writer, value.when)
        writer.endObject()
}

It has been addressed already but not released

@cortinico
Copy link
Collaborator Author

Thanks for the investigation @filipemp
Let's keep it open for now and wait for moshi 1.9.
If you have a branch ready, please send it out as a Draft PR and we can already do a first-pass review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
2 participants