Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a codec annotation to mark a sealed trait as having all case object members #506

Closed
googley42 opened this issue Feb 2, 2023 · 7 comments

Comments

@googley42
Copy link
Contributor

googley42 commented Feb 2, 2023

in zio-dynamodb (which is uses zio-schema) we have the @enumOfCaseObjects trait level annotation to signify that all members as case objects. This gets read by our codec generation code to produce a more compact encoding that is used in many legacy databases.

eg given this model:

sealed trait TrafficLight
case object GREEN extends TrafficLight 
case object RED extends TrafficLight
final case class Box(trafficLightColour: TrafficLight)

The default tagged union encoding is something like:

Map(trafficLightColour -> Map(String(GREEN) -> Null))

after you add the annotation to the sealed trait, the encoding is more compact, with one less level of indirection:

Map(trafficLightColour -> String(GREEN))

This issue is related to this one Define a canonical set of annotations that can be applied to sealed traits, case classes, and fields

@jdegoes
Copy link
Member

jdegoes commented Apr 25, 2023

Maybe @SimpleEnum to indicate all terms are case objects.

@jdegoes
Copy link
Member

jdegoes commented May 9, 2023

/bounty $75

@algora-pbc
Copy link

algora-pbc bot commented May 9, 2023

💎 $75 bounty created by jdegoes
🙋 If you start working on this, comment /attempt #506 to notify everyone
👉 To claim this bounty, submit a pull request that includes the text /claim #506 somewhere in its body
📝 Before proceeding, please make sure you can receive payouts in your country
💵 Payment arrives in your account 2-5 days after the bounty is rewarded
💯 You keep 100% of the bounty award
🙏 Thank you for contributing to zio/zio-schema!

Attempt Started (GMT+0) Solution
🟢 @pablf May 23, 2023, 12:34:35 PM #564

@andrzejressel
Copy link
Contributor

andrzejressel commented May 11, 2023

Weird, when working with JSON parser recently I swore I've seen code like that - if everything is sealed trait is CaseObject0 it deserialises as single string. I'll take a look later.

@pablf
Copy link
Member

pablf commented May 23, 2023

/attempt #506

@algora-pbc
Copy link

algora-pbc bot commented May 24, 2023

💡 @pablf submitted a pull request that claims the bounty. You can visit your org dashboard to reward.

@algora-pbc
Copy link

algora-pbc bot commented Sep 5, 2023

🎉🎈 @pablf has been awarded $75! 🎈🎊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants