grandstaish/paperparcel

Kotlin 1.1.0 - Java keywords can no longer be used as property names

bmoliveira opened this issue · 5 comments

Hi, after update to Kotlin 1.1.0 I'm getting this error:

error: Field NumberOfTasksAvailable._native_ is private and PaperParcel cannot find an accessor method for it. PaperParcel will search for accessor methods using the conventions defined at http://grandstaish.github.io/paperparcel/#model-conventions

My class is really simple and I was not getting this type of errors, what am I doing wrong?

@PaperParcel
@Model
data class NumberOfTasksAvailable(
    @Json(name = "copy")
    val copy: Int,

    @Json(name = "native")
    val native: Int,

    @Json(name = "paid")
    val paid: Int,

    @Json(name = "senior")
    val senior: Int,

    @Json(name = "total")
    val total: Int
) : PaperParcelable {
  companion object {
    @JvmField val CREATOR = PaperParcelNumberOfTasksAvailable.CREATOR
  }
}

Your class looks normal to me. What's @Model?

The error is saying there's a private property called _native_ in that class somehow. If you press cmd + shift + a and then type show kotlin bytecode, then click decompile, can you see a property called _native_? If you can, can you copy the decompiled class here so I can see it?

It might be something new that kotlin is doing, I'll have to find ask around and patch the library if that's the case.

OK, the issue is your property called native. Since native is a java keyword, kotlin (or kapt) is doing something weird with the name. This definitely didn't used to happen. For now, the workaround will be to rename that property to something that isn't a keyword.

Ok I see, but nice, thanks, for now I'll just rename the property for now

thank you very much

The @model is an annotation that we are using to Represent Parsable data models with Moshi, to verify that all the non-optional fields are present. (Sorry didn't saw your question earlier)

Fix will be in 2.0.1