Encoder should remove None: Option[T] values
See original GitHub issueIt would be nice if the Encoder would remove the key/value completely when the type is Option[T]
and the value is None
. Currently, it encodes None to JSON null.
(Json4s works this way.)
This code:
case class Test(foo: String, bar: Option[String])
implicit val testEncoder: Encoder[Test] = deriveEncoder
println(Test("FOO", None).asJson.noSpaces)
currently prints:
{"foo":"FOO","bar":null}
I would like it to be:
{"foo":"FOO"}
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (1 by maintainers)
Top Results From Across the Web
Remove --none-- option from dependant field - ServiceNow
Solved: Hello Experts, How to remove --none-- option from dropdown of dependant field? I have one field named "Stage". Values of this field....
Read more >Encoding Scala None to JSON value using circe
The best way to do this is probably just to add a post-processing step to a semi-automatically derived encoder for B : import...
Read more >How to hide "None" option single select custom field?
Hello Everone, I've made a single select custom field required. however, it is still showing the "None" option in the custom field. I've....
Read more >How to Remove '-None-' option from Select List Field?
Edit the filed and make one of the option as default value in the select list and Make it required field.
Read more >Python | Remove None values from list - GeeksforGeeks
There can be multiple methods to remove None values from a Python list. Some of them are discussed as follows: ...
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
I agree that
Printer
should not touch the JSON by default. I also agree thatPrinter
should have the power to make the result nicer if you want to. This could help in cases where the actual value isnull
(e.g. Java interop). So I thinkPrinter
is just fine as is.I think the encoder, though, should drop
None
values by default and not encode them asnull
. It should, however, encode genuinenull
values asnull
and not drop them.Similar to
dropNullKeys = false
inPrinter
, I think the encoder configuration can have something likedropNone = true
.What was the reason to make
dropNullKeys = false
by default? It seems that not putting nulls is more common among other libraries.