-
Notifications
You must be signed in to change notification settings - Fork 162
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
Fix JSON decoding of empty objects #710
Conversation
be4590d
to
116b786
Compare
- discriminated case object - case object with @rejectExtraField
f9bab51
to
d9a785c
Compare
@@ -991,7 +991,29 @@ object JsonCodec { | |||
import JsonCodec.JsonDecoder.schemaDecoder | |||
|
|||
private[codec] def caseClass0Decoder[Z](discriminator: Int, schema: Schema.CaseClass0[Z]): ZJsonDecoder[Z] = { (trace: List[JsonError], in: RetractReader) => | |||
if (discriminator == -1) Codecs.unitDecoder.unsafeDecode(trace, in) | |||
def skipField(): Unit = { | |||
val rejectExtraFields = schema.annotations.collectFirst({ case _: rejectExtraFields => () }).isDefined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calculating this every time may seem redundant, but skipField()
won't run at all in most cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still think we can make this a val on Schema.Record
. Maybe I should do this in my PR
@guersam ask algora ppl in the discord |
This PR fixes the decoding failure of discriminated case objects.
Example
It also makes case object decoding respect
@rejectExtraFields
.However, currently
@rejectExtraFields
can be applied only to the leaf nodes of ADTs, not the sealed trait/enum itself. To fix this, we need to propagate the parent schema to every caseClassN decoder, but it's out of the scope of this PR. (#700)/claim #711