-
Notifications
You must be signed in to change notification settings - Fork 623
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
Fix TaggedDecoder nullable decoding #2456
Fix TaggedDecoder nullable decoding #2456
Conversation
I also tried changing the existing serializers to nullable, but that breaks encoding since the AbstractEncoder (and other places) then assume that the serializer can take null as an input. Actually changing the serializers to nullable types, but it still breaks the |
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.
First note, that TaggedEncoder
through encodeNullableSerializableValue
already correctly supports the case of the serializer supporting nullability itself. This means the lack of support in TaggedDecoder
is a bug, not merely a potential feature.
The implementation however is incorrect in that it doesn't conform to the behavioural contract of nullable serializers (the test is broken to compensate). See the specific comments. The main decode function is easy to fix, but adding the overload for decodeNullableSerializableValue
that takes the previous value would be good.
formats/json-tests/commonTest/src/kotlinx/serialization/json/JsonElementDecodingTest.kt
Outdated
Show resolved
Hide resolved
formats/json-tests/commonTest/src/kotlinx/serialization/json/JsonElementDecodingTest.kt
Outdated
Show resolved
Hide resolved
formats/json-tests/commonTest/src/kotlinx/serialization/json/JsonElementDecodingTest.kt
Show resolved
Hide resolved
b709c0d
to
5d79745
Compare
Hi, thanks for your PR. Whether I'm in favor of the fix that will allow you to write a custom serializer like in your test to solve the problem. |
core/commonMain/src/kotlinx/serialization/encoding/AbstractDecoder.kt
Outdated
Show resolved
Hide resolved
c64ba4a
to
6264262
Compare
Yep, perfectly reasonable. While poking around in the decoders I realized that I probably have a very niche use-case and there doesn't seem to be an obvious way to integrate it without breaking things or introducing a configuration option specifically for this, which is probably not worth it.
I guess for the last changes I only ran the JSON tests. I reverted the value -> element change and executed allTest locally, all tests are passing here. |
@pschichtel Can you also please open your PR against |
6264262
to
af60d8d
Compare
@sandwwraith changed it |
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.
Thank you!
The implementation of decodeNullableSerializableElement of TaggedDecoder was inconsistent with AbstractDecoder, which made it impossible to use null-capable serializers as seen in the new tests. This partially fixes #2455 by allowing me to create a nullable version of the JsonElement serializer.