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

@JsonClassDiscriminator and other serial info annotations in sealed, polymorphic and object serializables #1515

Closed
wants to merge 4 commits into from

Conversation

sandwwraith
Copy link
Member

As of now, requires a special branch of the Kotlin compiler to work (will likely be merged in 1.5.20)

objectInstance: T,
classAnnotations: Array<Annotation>
) : this(serialName, objectInstance) {
(this.descriptor as SerialDescriptorImpl).annotations = classAnnotations.asList()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have the impression that this is not the best idea to do SerialDescriptorImpl almost mutable because of one issue.
Also, explicit conversion to SerialDescriptorImpl looks dangerous.
Maybe solve the problem where it appears - in serializer? Create private var property and rewrite it in the secondary constructor or other alternatives.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is, the secondary constructor is called after all init blocks and properties initializers. I considered the following alternatives:

  • Mutable (to some reasonable extent) serialDescriptorImpl — current solution. I can add buildSerialDescriptorInternal function to avoid downcast to be sure this won't break.
  • Store the builder in property, call .build on every access to public val descriptor — I don't like copying every time
  • Store descriptor in private mutable property, rebuild it from scratch (because we do not have a copying mechanism) every time. Seems reasonable, although a bit boilerplaite-ish. However, I do not see any strong objections to this solution, so I can rewrite everything to it

@sandwwraith sandwwraith requested a review from shanshin June 2, 2021 14:50
@sandwwraith
Copy link
Member Author

sandwwraith commented Jul 20, 2021

Superseded by #1608 as we changed the design

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

Successfully merging this pull request may close these issues.

2 participants