Environment:
$ crystal -v
Crystal 0.27.0 (2018-11-04)
LLVM: 6.0.1
Default target: x86_64-apple-macosx
Bug:
require "json"
hash = Hash(String, String | Nil).from_json %({"a":null})
puts hash # => {}
Bug-in-action:
@asterite Four years ago you implemented skipping null in Hash values (5312eed). However I think it is too implicit behavior and makes users confused (like this issue). Could you explain the reason?
I'm the spec example, the value type is Nil, so you can't add nil to the hash. I'd suppose it's okay for this use case to remove JSON nulls when the hash value is non-nilable.
But it should add nil if the value type includes Nil.
@MakeNowJust good finding! You can revert that commit. If V is a union it will now work fine. My change was before we could do union from json.
My change was before we could do union from json.
It is clear. Thank you!