Reading basic data values types from JSONNull values should trigger errors since values types in Scala are not nullable.
Currently, reading a JSONNull value produces the default value for given value type which is typically some form of zero. This is also inconsistent with JSON specification which defines null as a separate data type unrelated to number.
Environment
uPickle: 1.4.0
Scala: 3.0.0
JRE: 17
Reproduce
import ujson.Null
import upickle.default.read
object Main extends App:
// Produces default value for Int
def readValue = read[Int](Null)
println(s"\nread[Int](Null):\n$readValue")
// Interestingly, using the same expression in String interpolation produces null instead
val interpolated = s"\nInterpolated read[Int](Null):\n${read[Int](Null)}"
println(interpolated)
Reading basic data values types from JSON
Null
values should trigger errors since values types in Scala are not nullable.Currently, reading a JSON
Null
value produces the default value for given value type which is typically some form of zero. This is also inconsistent with JSON specification which defines null as a separate data type unrelated to number.Environment
Reproduce
Result
Expected
Fix
Add the following method override to each value type
Reader
(e.g.IntReader
):Workaround
Add the equivalent implicit overrides for each value type
Reader
to your custom configuration:ID: 355 Original Author: martin-ockajak