Skip to content
This repository has been archived by the owner on Aug 26, 2021. It is now read-only.

Stag with Kotlin Data Classes #192

Closed
reastland opened this issue Oct 1, 2019 · 3 comments
Closed

Stag with Kotlin Data Classes #192

reastland opened this issue Oct 1, 2019 · 3 comments

Comments

@reastland
Copy link

Issue Summary

In Kotlin, all data classes are marked as final classes when the app compiles. An error like this is thrown at compile time:

error: Unable to access field "whatever" in class com.example.stagtest.MyDataModel, field must not be final.

Reproduction Steps

@UseStag
data class ApiResponse(val dates: List<Day>, val totalGames: Int) {

    @UseStag
    data class Day(
        val totalGames: Int, // 14
        val games: List<Game>
    )
}

Attempt to compile.


Expected Behavior

App compiles to completion.

Actual Behavior

Throws an error:

/Users/me/StagDeserializationPrototype/app/build/tmp/kapt3/stubs/debug/com/example/stagdeserializationprototype/ApiResponse.java:92: error: Unable to access field "totalGames" in class com.example.stagdeserializationprototype.ApiResponse.Day, field must not be final.
private final int totalGames = 0;

@ToxicBakery
Copy link

It's not complaining about the field it's complaining about the usage of val. Unfortunately, you can not have final values and must use var

@anthonycr
Copy link
Contributor

I would suggest using moshi-kotlin-codegen with kotlin DTOs. In order to use stag, you must make you make the properties mutable var as @ToxicBakery correctly pointed out.

@anthonycr
Copy link
Contributor

Closing as duplicate of #191

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

No branches or pull requests

3 participants