com-lihaoyi / upickle

uPickle: a simple, fast, dependency-free JSON & Binary (MessagePack) serialization library for Scala
https://com-lihaoyi.github.io/upickle
MIT License
722 stars 165 forks source link

Allow `$type` tag to be replaced by some other string (500USD Bounty) #578

Closed lihaoyi closed 6 months ago

lihaoyi commented 6 months ago

Given a "$type": "foo.Bar" sealed trait discriminator, Custom Keys's @key annotation allows you to replace the right hand side "foo.Bar" of a particular case class by annotating the case class, but it does not allow you to replace to left hand side "$type" string with something else.

This ticket is to implement the ability for a user to replace $type" with some other string, by annotating the sealed trait itself with @key("myType") annotation that would replace "$type" with "myType" for all sub-classes of the sealed trait.

To incentivize contribution, I'm putting a 500USD bounty on resolving this ticket. This is payable via bank transfer, and at my discretion in case of ambiguity.

mrdziuban commented 6 months ago

I'd be happy to take a stab at this @lihaoyi

Is it okay if the LegacyApi continues to use $type for the discriminator and only upickle.default uses the new behavior?

lihaoyi commented 6 months ago

IIRC the legacy one doesnt use a key value discriminator at all; instead, it wraps things jn two element arrays

lihaoyi commented 6 months ago

But yeah, I think in general focusing on making it work for upickle.default is fine.