Regression: Converter on nilable field in JSON::Serializable
fails when reading null
value
#13655
Labels
kind:bug
A bug in the code. Does not apply to documentation, specs, etc.
kind:regression
Something that used to correctly work but no longer works
topic:stdlib:serialization
Milestone
Some of the refactoring in
JSON::Serializable
(probably #13433) breaks readingnull
values on a nilable field when using a converter.The following code works fine in 1.8.2 but raises in 1.9.0:
Fields without a converter are unaffected because the deserializer tries to deserialze each of the union types. That includes
Nil
and it succeeds returningnil
.This was discovered in https://forum.crystal-lang.org/t/json-serializable-converters-and-nilable-values/5828
A potential workaround is to wrap the converter with explicit
null
handling:Perhaps this would even be a better way to implement this, being more explicit and giving full control of
null
handling to the converter.But it used to work that
null
are implicitly read and turned innil
for nilable fields, so this should be restored.The text was updated successfully, but these errors were encountered: