Shorten $type
tag used for discriminating sealed trait
cases
#596
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #527
This PR shortens the
"$type": "foo.bar.Qux"
tag that uPickle uses to distinguish between cases of asealed trait
, down to"$type": "Qux"
or"$type": "bar.Qux"
. Because thetrait
issealed
, upickle is able to look at all the other cases, and picks the shortest partially-qualified name that is enough to distinguish all the different cases. As mentioned in the original issue, this makes the serialization format more compact, more robust against code changes (e.g. changes inpackage
name), and it homogenizes the serialization format ofsealed trait
hierarchies and Scala 3enum
s (which already use a short partially-qualified name as the$type
tag)Despite being binary compatible at the JVM level, this is a backwards incompatible change that will need to go into uPickle 4.x. To ease the rollout, the implementation is able to read both old-style fully qualified
$type
tags as well as new-style partially-qualified$type
-tags, and whether new-style output or old-style output is generated during serialization is controlled by aobjectTypeKeyWriteFullyQualified
flag.Someone migrating to uPickle 4.x from upickle 3.x can preserve the existing read/write behavior by replacing
upickle.default
with aCustomPickler
withobjectTypeKeyWriteFullyQualified = true
, roll it out across their system so their entire system can read both old-style and new-style$type
tags, and then flip individual components toobjectTypeKeyWriteFullyQualified = false
(or back toupickle.default
). The system will work correctly with a mix of old-style and new-style$type
tags being generated, until everything is on new-style$type
tags.