-
Notifications
You must be signed in to change notification settings - Fork 640
MissingFieldException when trying to deserialize enum field in sealed hierarchy #2909
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
Comments
Yes, that indeed looks like a bug |
I managed to get a little closer to the problem.
And that is ok:
When parsing JsonElement (which fails), JsonTreeDecoder is used, and StreamingJsonDecoder is used with string |
If you try to manually deserialize in such manner
When parsing json element index will be -1 |
This condition inside kotlinx.serialization.json.internal.JsonTreeDecoder#decodeElementIndex seems broken? It looks like ! before configuration.coerceInputValues not needed. Or i missed something? |
in cases when a property is nullable and not optional, and explicitNulls is set to false. Fixes #2909
Describe the bug
Exception occurred when trying to deserialize object as sealed root, if it contains field with unknown enum value.
Exception in thread "main" kotlinx.serialization.MissingFieldException: Field 'status' is required for type with serial name 'org.example.Feature', but it was missing at path: $
To Reproduce
If try to decode as concrete impl, than all is ok
parser.decodeFromString<TestSealed.FirstSealed>(json)
Also noticed that moving "type" key up - fixes the problem. Does the order of keys is important?
Expected behavior
Decode success, and prints:
FirstSealed(feature=Feature(status=null))
Environment
The text was updated successfully, but these errors were encountered: