Skip to content
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 decoding an optional Document.DNull field #725

Merged
merged 2 commits into from
Jan 13, 2023
Merged

Fix decoding an optional Document.DNull field #725

merged 2 commits into from
Jan 13, 2023

Conversation

zetashift
Copy link
Contributor

@zetashift zetashift commented Jan 13, 2023

Fixes: #697

Test was made from kubukoz's reproduction example:

//> using scala "3.2.1"
//> using lib "com.disneystreaming.smithy4s::smithy4s-core:0.17.2"
import smithy4s.schema.Schema
import smithy4s.Document

@main def demo = println {
  val optionalFieldSchema =
    Schema
      .struct[Option[String]](Schema.string.optional[Option[String]]("test", identity))(identity)

  Document
    .Decoder
    .fromSchema(optionalFieldSchema)
    .decode(Document.obj("test" -> Document.DNull))
}

@@ -323,6 +322,7 @@ class DocumentDecoderSchemaVisitor(
val path = PayloadPath.Segment(jLabel) :: pp
fields
.get(jLabel) match {
case Some(DNull) => buffer(None)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: this is exactly what I was thinking, how dare you steal my ideas :P /s

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, great minds think alike? 👀

@kubukoz kubukoz merged commit 718ece4 into disneystreaming:series/0.17 Jan 13, 2023
@kubukoz
Copy link
Member

kubukoz commented Jan 13, 2023

Thanks for the contribution @zetashift!

@zetashift zetashift deleted the fix/optional-field-dnull branch January 13, 2023 18:07
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

Successfully merging this pull request may close these issues.

Decoding an optional field fails when receiving a Document.DNull
2 participants