Do Not Attempt Decoding When We Know It Will Fail #230
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit changes the
orDefault
andorDefaultAccumulating
methods to not attempt decoding when we,The code is made a bit more complex and less optimal because we have to run the decoder when the value is
null
, though we don't when it is missing. This is because the CirceDecoder[Option[A]]
has a special case for this input{"a": null}
. All other types would consider the valuenull
and the missing key"a"
to be the same case and use a default, butDecoder[Option[A]]
considers{"a": null}
asRight(None)
.See the test
"Option[T] with default should be None if null decoded"
for a complete example.In the future, for defaulting codecs, we might consider treating a missing value and
JNull
the same in all cases, even forOption
.This commit also adds a benchmark package which was used to verify the issue referenced in circe/circe#1972.
Note, this optimization works around the issue in circe/circe#1972, but there is still an issue in circe proper for circe/circe#1972. This optimization is good with or without the issue described in circe/circe#1972.