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

KSP2: Exception when using Moshi KSP and @ JsonQualifier #2019

Closed
Jean-Daniel opened this issue Jul 31, 2024 · 1 comment
Closed

KSP2: Exception when using Moshi KSP and @ JsonQualifier #2019

Jean-Daniel opened this issue Jul 31, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@Jean-Daniel
Copy link

Note: This issue was originally reported on Moshi, but was determined to be a KSP issue from Moshi devs.

When trying to generate Adapter for classes using a @JsonQualifier, KSP fails with the error:


> Task :app:kspDebugKotlin FAILED
e: [ksp] Error preparing ApiUserItem: jdk.proxy5/jdk.proxy5.$Proxy154.value(Unknown Source)
com.squareup.moshi.kotlin.codegen.ksp.MoshiApiUtilKt.generator(MoshiApiUtil.kt:77)
com.squareup.moshi.kotlin.codegen.ksp.JsonClassSymbolProcessor.adapterGenerator(JsonClassSymbolProcessorProvider.kt:122)
com.squareup.moshi.kotlin.codegen.ksp.JsonClassSymbolProcessor.process(JsonClassSymbolProcessorProvider.kt:92)
com.google.devtools.ksp.impl.KotlinSymbolProcessing.execute(KotlinSymbolProcessing.kt:538)
com.google.devtools.ksp.impl.KSPLoader$Companion.loadAndRunKSP(KSPLoader.kt:36)
com.google.devtools.ksp.impl.KSPLoader.loadAndRunKSP(KSPLoader.kt)
…

The class being compiled is simply:

@Retention(AnnotationRetention.RUNTIME)
@JsonQualifier
annotation class ISO8061

@JsonClass(generateAdapter = true)
open class ApiUserItem(
  @field:Json(name = "slug") val slug: String,
  @field:Json(name = "date_added") @field:ISO8061 val date: Long,
)

You can use this reduced test case to reproduce the bug.

git clone https://github.com/Jean-Daniel/moshiksp2
cd moshiksp2
./gradlew :app:assembleDebug
> Task :app:kspDebugKotlin FAILED
…
@ting-yuan ting-yuan added the bug Something isn't working label Jul 31, 2024
@ting-yuan ting-yuan self-assigned this Jul 31, 2024
@ting-yuan
Copy link
Collaborator

ting-yuan commented Jul 31, 2024

This is caused by a breaking change in KSP2, where enums in annotations are modeled as KSClassDeclaration, instead of KSType in KSP1. It should be easy for moshi to delete the proxy implementation and simply use KSP's.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants