package foo
sealed trait Bar
case class Qux() extends Bar
case class Baz() extends Bar
We currently serialize Qux() and Baz() to
{"$type": "foo.Qux"}
{"$type": "foo.Baz"}
We should instead serialize them to
{"$type": "Qux"}
{"$type": "Baz"}
As long as all the cases of the sealed trait are in the same namespace (foo above), using the short name is safe.
It also has several advantages: it is easier to read, results in more compact JSON, and is more stable in case the pacakge foo gets renamed to foo2.
The serialization would still be broken if e.g. Baz got moved into package sub{ case class Baz() }, but that is (a) already the case today and (b) this is sufficiently uncommon a refactor that it's probably not worth worrying about
This would be a breaking change in the serialization format and would need to wait for upickle 4.0.0
Given
We currently serialize
Qux()
andBaz()
toWe should instead serialize them to
As long as all the
case
s of thesealed trait
are in the same namespace (foo
above), using the short name is safe.It also has several advantages: it is easier to read, results in more compact JSON, and is more stable in case the pacakge
foo
gets renamed tofoo2
.The serialization would still be broken if e.g.
Baz
got moved intopackage sub{ case class Baz() }
, but that is (a) already the case today and (b) this is sufficiently uncommon a refactor that it's probably not worth worrying aboutThis would be a breaking change in the serialization format and would need to wait for upickle 4.0.0