-
Notifications
You must be signed in to change notification settings - Fork 625
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
Default polymorphic type handler for deserialization not working for Protobuf #2598
Comments
There is an error in your class: The polymorphic serializer works by injecting a synthetics structure with 2 members: type and value. Formats can then hide this by having a special type member/attribute (as such the json deserialization works by accident - it can't distinguish between the generated (and inlined) type attribute and the explicit type attribute that is part of |
Yes, I think that the problem is that Also, pay attention that only Json supports polymorphism with an embedded 'type' key. Other formats use default polymorphism, which is array-based (see PolymorphicSerializer.descriptor structure) |
There are 2 things I'd like to explain for this. Firstly, after either I remove all the
And secondly, I was actually doing this intentionally. As you both explained:
So |
I see. So, the input is:
(you can use https://protogen.marcgravell.com/decode to get this kind of info) And you're trying In that case, I do not see how |
This comment was marked as outdated.
This comment was marked as outdated.
Oh I think I get what went wrong (for details see the hidden comment above). After I remove @Serializable
data class BasicProject(@ProtoNumber(2) override val name: String) : Project() So does this mean that with Protobuf I can't deserialize |
Yes, in the case of default (array) polymorphic serialization you cannot access
It is for Json. If you enable deprecated |
@sandwwraith Thank you very much for clarifying. I shall close this issue then. I think it might be helpful to point this out in the guide here, however. |
I had a look at the guide. The use of
|
…er` and make it work See Kotlin#2598.
Describe the bug
Default polymorphic type handler for deserialization is not working for Protobuf. Originally found while working on #2587 here.
To Reproduce
Attach a code snippet or test data if possible.
Code (adpated from example-poly-19.kt):
Output:
Expected behavior
Environment
Commit 1f7372a of this project.
The text was updated successfully, but these errors were encountered: