com-lihaoyi / upickle

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

Make Option[T] in case classes un-boxed by default #528

Closed lihaoyi closed 2 months ago

lihaoyi commented 1 year ago

Currently we serialize them as k: [v] or k: [], which is generally not what people want. We should instead serialize them as k: v or nothing.

Nested options could probably continue to be serialized boxed in a single-element array. Options in sequences and other things that serialize to arrays can conitnue to be boxed as well.

This would be a breaking change and would need to go into upickle 4.0.0

nemoo commented 9 months ago

Oh yes, please! The lack of serialization of a not existing option to nothing is what prevents me from using upickle as my general-purpose json lib.

If you want to use upickle to expose an http API serving json, the expectation is that for a missing option, you can just drop the field.

Because that is how most APIs work in the real world. For that reason I default to using Play Json for APIs currently.