Kotshi kapt fails to find @KotshiConstructor annotated constructor
LouisCAD opened this issue · 2 comments
LouisCAD commented
The compilation error strikes with this:
import se.ansman.kotshi.JsonSerializable
import se.ansman.kotshi.KotshiConstructor
import splitties.exceptions.unsupported
@JsonSerializable
@Suppress("DataClassPrivateConstructor")
data class FcmToken private constructor(val androidId: String, val token: String, val appId: Int) {
constructor(androidId: String, token: String) : this(androidId, token, 857930)
@Suppress("UNREACHABLE_CODE")
@KotshiConstructor
constructor() : this(unsupported(), unsupported())
}
In the snippet above, unsupported()
returns Nothing
, just like Kotlin's TODO()
. The goal is to enforce the fact that this model is only for serialization, not parsing.
Here's the error:
:app:kaptGenerateStubsDebugProdApiKotlin
e: C:\Users\Me\AndroidStudioProjects\MyProject\app\build\tmp\kapt3\stubs\buildType\my\package\name\model\api\FcmToken.java:8: error: Kotshi: Multiple constructors found, please annotate the primary one with @KotshiConstructor
public final class FcmToken {
^
:app:kaptDebugProdApiKotlin FAILED
FAILURE: Build failed with an exception.
ansman commented
This is not supported at all, perhaps we it would be in the future by using annotation arguments.
LouisCAD commented
Tried to workaround this by adding a nothing: Nothing
parameter, but it seems I can't really, because there's a mismatch between the constructor parameter names and the properties on the class.