-
Notifications
You must be signed in to change notification settings - Fork 47
fix-polymorphic-value-class-union-schema-name #479
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
0131c11
d0ffbaa
bd46068
1c89c23
50ba4ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -332,6 +332,7 @@ public class KotlinGenerator( | |
| * ```kotlin | ||
| * @Serializable | ||
| * sealed interface <potentialAnonymousBaseName>Union { | ||
| * @AvroAlias("<Type full name>") | ||
| * @JvmInline | ||
| * @Serializable | ||
| * value class For<Type name>(val value: <Type full name>) : <potentialAnonymousBaseName>Union | ||
|
|
@@ -356,6 +357,7 @@ public class KotlinGenerator( | |
| TypeSpec.classBuilder(unionSubTypeNameFormatter(if (hasSimilarNames) subSchema.fullName else subSchema.simpleName.toPascalCase())) | ||
| .addSuperinterface(ClassName.fromFullName(className)) | ||
| .addModifiers(KModifier.VALUE) | ||
| .addAnnotationIfNotNull(buildAvroAliasAnnotation(listOf(subSchema.fullName))) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avro aliases are avro aliases, not for workaround. What are you trying to solve with this alias? Because the polymorphic resolver should actually resolve this workaround |
||
| .addAnnotation(JvmInline::class) | ||
| .addAnnotation(Serializable::class) | ||
| .addPrimaryProperty( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| ExperimentalAvro4kApi::class, | ||
| ) | ||
|
|
||
| import com.github.avrokotlin.avro4k.AvroAlias | ||
| import com.github.avrokotlin.avro4k.AvroDefault | ||
| import com.github.avrokotlin.avro4k.ExperimentalAvro4kApi | ||
| import com.github.avrokotlin.avro4k.InternalAvro4kApi | ||
|
|
@@ -25,18 +26,21 @@ public data class ComplexUnionInRecord( | |
| @Serializable | ||
| @AvroGenerated("""["null",{"type":"record","name":"NestedRecord","fields":[{"name":"id","type":"string"},{"name":"value","type":"int"}]},{"type":"enum","name":"Status","symbols":["ACTIVE","INACTIVE","PENDING"]},{"type":"array","items":"string"}]""") | ||
| public sealed interface TheFieldUnion { | ||
| @AvroAlias("NestedRecord") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't forget to re-run
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok done! thx for the review :-D
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But why the avro alias annotation is still present? |
||
| @JvmInline | ||
| @Serializable | ||
| public value class ForNestedRecord( | ||
| public val `value`: NestedRecord, | ||
| ) : TheFieldUnion | ||
|
|
||
| @AvroAlias("Status") | ||
| @JvmInline | ||
| @Serializable | ||
| public value class ForStatus( | ||
| public val `value`: Status, | ||
| ) : TheFieldUnion | ||
|
|
||
| @AvroAlias("array") | ||
| @JvmInline | ||
| @Serializable | ||
| public value class ForArray( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here you are trying to resolve a descriptor to its schema name. The best is to pass a
schemaNameResolver: (SerialDescriptor) -> String, and in the Avro class, pass{ schema(it).name }as there are many things to do to resolve a name. Example: for Fixed type, it's a ByteArray with the@AvroFixedannotation. any type with@AvroStringis finally a string. etc