-
Notifications
You must be signed in to change notification settings - Fork 620
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
Properties inherit from parent class which use custom serializer not serialized #1043
Comments
Indeed, plugin-generated serializers for inheritors usually delegate to parents' serializers — but in case of custom serializer plugin doesn't know how to delegate. So, the workaround for now is to write custom serializer for inheritor too. Btw, your custom serializer is incorrect: indices in |
Thank you for your explantation. The limitation results in writing custom serializer for every child class. One solution is to use composite instead of inheritance, but possibly there is a limitation either: the data class should be consistent with JSON structure defined by 3rd-party API provider. I corrected the index in my demo code. |
Is this issue on any road map to be fixed? /Thomas |
I don't think that it can be "fixed" at all. The only thing that could be done is for the serializer of the child type to pretend that the parent would be serialized by default (but why then use a custom serializer). As to supporting inheritance, for serialization you would probably want to have a protected function that would write only the properties, but not the structure (the bit in Btw. for naming just use |
Thanks for the quick reply. We have a generic Response (Kotlin implementation of Google JSON Style Guide https://google.github.io/styleguide/jsoncstyleguide.xml) that all our Micro Services uses a a payload base. So all public payload inherits from this Response class. In the Response class we have some computed properties that we would like to serialize so that is why I created my own KSerializer. |
@thol01 The way I see this is that conceptually you would transform the |
Thanks 🤩 |
Describe the bug
The properties inherit from parent class are not serialized if parent class use custom serializer.
To Reproduce
If use default serializer generated by plugin, works fine:
If use custom serializer, derived class lack of properties from base class:
The test code:
Expected behavior
using custom serializer when serialize
Environment
The text was updated successfully, but these errors were encountered: