You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello,
I used to use this plugin by letting it generate all models in one kotlin file, which worked great until I had to serialise a json that contains multiple fields named data, which results in multiple inner classes of the same name.
@JsonClass(generateAdapter =true)
data classTest(
@Json(name ="data")
val `data`: List<Data?>? = null,
...
) {
@JsonClass(generateAdapter =true)
data classData(
...
) {
...
@JsonClass(generateAdapter =true)
data classSomeInnerClass(
@Json(name ="data")
val `data`: Data? = null
) {
@JsonClass(generateAdapter =true)
data classData(
...
)
}
...
While the generated file passes the IDE's compile-checks, because the kotlin compiler is smart enough to apply the correct scope of each subclass, the kapt processor explodes.
Caused by: java.lang.IllegalStateException: No type element found for: <my.class.package>.Data.
at com.squareup.moshi.kotlinpoet.metadata.classinspectors.ElementsClassInspector.declarationContainerFor(ElementsClassInspector.kt:115)
at com.squareup.moshi.kotlinpoet.metadata.specs.ClassInspectorKt.classFor(ClassInspector.kt:112)
at com.squareup.moshi.kotlinpoet.metadata.specs.KotlinPoetMetadataSpecs.toTypeSpec(KotlinPoetMetadataSpecs.kt:470)
at com.squareup.moshi.kotlinpoet.metadata.specs.KotlinPoetMetadataSpecs.toTypeSpec(KotlinPoetMetadataSpecs.kt:476)
at com.squareup.moshi.kotlinpoet.metadata.specs.KotlinPoetMetadataSpecs.toTypeSpec(KotlinPoetMetadataSpecs.kt:476)
at com.squareup.moshi.kotlinpoet.metadata.specs.KotlinPoetMetadataSpecs.toTypeSpec(KotlinPoetMetadataSpecs.kt:476)
at com.squareup.moshi.kotlinpoet.metadata.specs.KotlinPoetMetadataSpecs.toTypeSpec(KotlinPoetMetadataSpecs.kt:182)
at com.squareup.moshi.kotlinpoet.metadata.specs.KotlinPoetMetadataSpecs.toTypeSpec$default(KotlinPoetMetadataSpecs.kt:178)
at com.squareup.moshi.kotlin.codegen.apt.MoshiCachedClassInspector.toTypeSpec(MoshiCachedClassInspector.kt:47)
at com.squareup.moshi.kotlin.codegen.apt.MetadataKt.targetType(metadata.kt:205)
at com.squareup.moshi.kotlin.codegen.apt.JsonClassCodegenProcessor.adapterGenerator(JsonClassCodegenProcessor.kt:141)
at com.squareup.moshi.kotlin.codegen.apt.JsonClassCodegenProcessor.process(JsonClassCodegenProcessor.kt:107)
at org.jetbrains.kotlin.kapt3.base.incremental.IncrementalProcessor.process(incrementalProcessors.kt:90)
at org.jetbrains.kotlin.kapt3.base.ProcessorWrapper.process(annotationProcessing.kt:197)
at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:985)
... 44 more
When generating from the same json but allowing multiple files, the duplicated classes are renamed appending an increasing number of X, which works great with kapt but forces me to have hundreds of files, which is not ideal.
Is there any workaround for this so far, or would it be possible in the future to force the plugin to append the Xs to duplicated class names even when using a single file?
The text was updated successfully, but these errors were encountered:
Hello,
I used to use this plugin by letting it generate all models in one kotlin file, which worked great until I had to serialise a json that contains multiple fields named
data
, which results in multiple inner classes of the same name.While the generated file passes the IDE's compile-checks, because the kotlin compiler is smart enough to apply the correct scope of each subclass, the
kapt
processor explodes.When generating from the same json but allowing multiple files, the duplicated classes are renamed appending an increasing number of
X
, which works great with kapt but forces me to have hundreds of files, which is not ideal.Is there any workaround for this so far, or would it be possible in the future to force the plugin to append the
X
s to duplicated class names even when using a single file?The text was updated successfully, but these errors were encountered: