zio-schema
zio-schema copied to clipboard
Rationalize handling of nested Optional schemas
Currently if we have a nested Optional
schema such as Schema.Optional(Schema.Optional(Schema.primtive(StandardType.StringType))
we cannot distinguish between the JSONprotobuf encodings of Some(None)
and None
which will both be encoded to null
in JSON (and similarly for protobuf).
As a first order issue this will cause test failures when we do a "round-trip" encoding/decoding of Some(None
which will encode to null
and then decode to just plain None
instead of Some(None)
.
A couple of options for handling this:
- Use a type constraint to prevent "nesting" of optional schemas
trait Schema[A] {. self =>
def optional(implicit ev: A <:!< Option[Any]): Schema.Optional[Option[A]]
}
This generalized type constraint doesn't exist in Scala so we'd have to create it
- Allow nested optional schemas but make it so
Some(None) == None
in the specs.