Skip to content

Kotlin - kotlinx.serialization - polymorphism #14301

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

loicsiret
Copy link

@loicsiret loicsiret commented Dec 20, 2022

Currently Kotlin multiplatform didn't support Polymorphic Serializer.
I have implemented the polymorphic support by using JsonContentPolymorphicSerializer from kotlinx.serialization
You can check the sample : samples/client/petstore/kotlin-multiplatform-polymorphic

internal object AnimalSerializer : JsonContentPolymorphicSerializer<Animal>(Animal::class) {
    override fun selectDeserializer(element: JsonElement) = when {
        "BIRD" in element.jsonObject["type"].toString() -> Bird.serializer()
        else -> Animal.serializer()
    }
}

One thing I'm not confident is the modification in data_class.mustache concerning the use of the parent constructor

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master (6.3.0) (minor release - breaking changes with fallbacks), 7.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.
  • Technical committee :
    @jimschubert, @dr4ke616 @karismann @Zomzog @andrewemery @4brunu @yutaka0m

#14548

lsiret and others added 4 commits December 20, 2022 14:06
The Serializer check the mapping value in the discriminator field
of the json we received to find the children Serializer
@thejeff77
Copy link

Would really love to see this change get in.

@wing328
Copy link
Member

wing328 commented Aug 6, 2023

@loicsiret thanks for the PR. Can you please PM me via Slack to discuss this further?

https://join.slack.com/t/openapi-generator/shared_invite/zt-12jxxd7p2-XUeQM~4pzsU9x~eGLQqX2g

@snowe2010
Copy link
Contributor

Did this conversation happen?

@loicsiret
Copy link
Author

loicsiret commented Aug 14, 2023 via email

@wing328 wing328 modified the milestones: 7.0.0, 7.0.1 Aug 25, 2023
@wing328 wing328 modified the milestones: 7.0.1, 7.1.0 Sep 19, 2023
@wing328
Copy link
Member

wing328 commented Oct 3, 2023

@snowe2010 if you've time to contribute a test or 2, please reply to let us know.

@contradictioned
Copy link

I am not snowe2010, however I'd be interested in helping with some tests.

@loicsiret
Copy link
Author

loicsiret commented Oct 26, 2023 via email

@wing328 wing328 modified the milestones: 7.1.0, 7.2.0 Nov 13, 2023
@wing328 wing328 modified the milestones: 7.2.0, 7.3.0 Dec 22, 2023
@wing328 wing328 modified the milestones: 7.3.0, 7.4.0 Feb 8, 2024
@wing328 wing328 removed this from the 7.4.0 milestone Mar 11, 2024
@RuterFrode
Copy link

Two years since this PR was opened. Why not merged?

@wing328
Copy link
Member

wing328 commented Jan 9, 2025

@RuterFrode there's no test added in this PR.

Can you file a new PR on top of this one and add some tests please?

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

Successfully merging this pull request may close these issues.

6 participants