8000 [generic extras] Default value of Option is ignored · Issue #878 · circe/circe · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[generic extras] Default value of Option is ignored #878

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

Closed
ryamaguchi0220 opened this issue Apr 10, 2018 · 3 comments
Closed

[generic extras] Default value of Option is ignored #878

ryamaguchi0220 opened this issue Apr 10, 2018 · 3 comments

Comments

@ryamaguchi0220
Copy link
ryamaguchi0220 commented Apr 10, 2018

Hi, The following code returns Right(Foo(a, None)) 
but, I expect Right(Foo(a, Some(0)))

Is this a bug, or am I doing something wrong?

import io.circe.generic.extras.auto._
import io.circe.generic.extras.Configuration

implicit val customConfig: Configuration = Configuration.default.withDefaults

case class Foo(a: String = "a", b: Option[Int] = Some(0))
io.circe.parser.decode[Foo]("{}")

My dependencies.

"io.circe" %% "circe-core" % "0.9.3"
"io.circe" %% "circe-generic" % "0.9.3"
"io.circe" %% "circe-parser" % "0.9.3"
"io.circe" %% "circe-generic-extras" % "0.9.3"

Thanks.

@travisbrown travisbrown modified the milestone: 0.10.0 May 31, 2018
@travisbrown
Copy link
Member

For the record, I think I would probably consider this a bug, but it's a somewhat complex one, because the default is used when decoding a member fails, but decoding an optional member that's not there doesn't fail. I'd like to see a fix for this, but I'm not sure it'll happen before 0.10.0.

@ryamaguchi0220
Copy link
Author
ryamaguchi0220 commented Jun 7, 2018

This can be avoided by defining a custom decoder.
However, it would be helpful not to need to define a custom decoder.

@niij
Copy link
niij commented Dec 4, 2018

This is an issue for me as well. Is it possible to add an option to Configuration like withDefaultsForOptions?

@ryamaguchi0220 ryamaguchi0220 changed the title [generic extras] Default value of Option type will be ignored [generic extras] Default value of Option is ignored Dec 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
0