Comments (8)
@trane It's not necessarily obvious that a derived decoder will use default constructor values (when they're needed), and if that's not the behavior you want, it could be an unpleasant surprise. But I agreeโI think it makes sense to use them (with plenty of documentation) in auto
, and to provide something like decoderWithoutDefaults
in semiauto
.
from circe.
This is now available in circe-extras in 0.6.0-RC1.
from circe.
Something like milessabin/shapeless#459 would allow to address that (default field values can easily be pulled like in this test).
from circe.
One general question: should this be the behavior provided by generic.auto
(if default values are available in the Default
instance, use them), or should it be an option provided by semiauto
?โi.e. something like this:
implicit val decodeBar: Decoder[Bar] = deriveFor[Bar].decoderWithDefaults
from circe.
I don't know what the benefit is to having it in semiauto
. The least surprising option, from my point of view, is to treat case class X
with/without defaults the same way.
from circe.
@travisbrown don't trust my point of view, I've been coding in Ruby for the past 2 years -- of course I like magic and surprising behavior!
from circe.
@travisbrown @trane Was this ever added by any chance? I was playing around this morning and hit this issue so was unsure if I am missing something?
from circe.
@travisbrown I was figuring out how it can be implemented and ended up with the following.
Inside DerivationMacros#decodeHList
and DerivationMacros#decodeCoproduct
we should check whether the class has default values, and if it has, add them to representation.
Am I on the right path?
If so, can you give any tips in how it can be done?
from circe.
Related Issues (20)
- Cannot derive `Decoder` for case class with inserction type fields HOT 1
- `BiggerDecimal.parseBiggerDecimalUnsafe` throws `NumberFormatException` HOT 1
- Bad encoding of Option in scala 2.12 HOT 1
- Decoding compilation fails for tagged types with Circe > 0.14.3 HOT 3
- Derivation doens't apply Configuration HOT 4
- Support new configuration that handles digit as a delimiter when converting to snake_case HOT 1
- How do I map a particular key and value in a custom way? HOT 2
- io.circe.pointer.literal.PointerInterpolatorSuite seems Flaky (or there's a bug?) HOT 2
- Maximal number of successive inlines (32) exceeded, Maybe this is caused by a recursive inline method? HOT 7
- Circe cannot decode output from auto-derived codec on Scala 3 HOT 1
- Scala3 derivation incorrectly assumes collection type for generic class HOT 4
- Stack overflow on 0.14.6 HOT 4
- Unexpected derivation of Encoder[Option[T]]
- Modifying JsonObject using ACursor/HCursor performance hit due to megamorphic calls HOT 1
- Invalid Json tree with `null` (java) values, NPE in printer HOT 1
- a problem with current derivations HOT 7
- Properly parse JSON object key with quotes HOT 1
- usage of ISO_ZONED_DATE_TIME as default formatter in encoder HOT 3
- Scala 2.13: derivedConfiguratedEncoder becomes unconfigured under some conditions HOT 1
- Expected `json` string interpolator from io.circe.literal to be able to interpolate variable inside of value strings HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from circe.