Why will upickle convert `Option[T]` to array `[...]`?
See original GitHub issueI found if there is an option value in case class, it will be converted to []
in js
case class User(name:String, age: Option[Int])
val user1 = User("Free", Some(100))
val user2 = User("Wind", None)
Will be converted to:
{ "name": "Free", "age": [100] }
{ "name": "Wind", "age": [] }
Why use array here rather than:
{ "name": "Free", "age": 100 }
{ "name": "Wind" }
The later is the one I usually do with other scala json libraries
Issue Analytics
- State:
- Created 9 years ago
- Comments:13 (7 by maintainers)
Top Results From Across the Web
Why will upickle convert Option[T] to array [...] ? #75 - GitHub
I found if there is an option value in case class, it will be converted to [] in js case class User(name:String, age:...
Read more >lihaoyi/upickle - Gitter
I have a problem using upickle with type aliases in a cake pattern. ... to override the Option value from scala My options...
Read more >µPickle 2.0.0
uPickle (pronounced micro-pickle) is a lightweight JSON and binary (MessagePack) serialization library for Scala. It's key features are:.
Read more >Li Haoyi on Twitter: "uPickle can also parse/serialize any of ...
uPickle 0.6.0 can convert *between* JSON ASTs from any of the different ... byte-arrays or files Performance often isn't quite as good as...
Read more >How to parse a json string to a case class in scaja.js and vice ...
Use one of the pickling libraries that work with Scala.js. The following two produce well-behaved and predictable JSON: uPickle · Prickle.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This writer is applied for
Some(v)
:This one too :
But these are not :
Unfortunately generic types doesn’t work at all, so I have to list a custom writer for each type :
It would be cool if it worked even for
String
andInt
… any idea ?One common use case would be a reader for
so that
undefined
is parsed too :Last solution from @asdcdow does this
Modifying
MyCC
with DefaultsI get what I expect