Skip to content

Commit

Permalink
Fix the json decoder for case classes that only have None fields. (#…
Browse files Browse the repository at this point in the history
…677)

Co-authored-by: Nabil Abdel-Hafeez <[email protected]>
Co-authored-by: Milad Khajavi <[email protected]>
  • Loading branch information
3 people authored May 17, 2024
1 parent fffdab0 commit e24f38a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1344,7 +1344,7 @@ object JsonCodec {

if (discriminator == -1) {
Lexer.char(trace, in, '{')
loop(0, in)
if (Lexer.firstField(trace, in)) loop(0, in)
} else if (discriminator == -2) {
if (Lexer.nextField(trace, in)) loop(0, in)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1121,6 +1121,9 @@ object JsonCodecSpec extends ZIOSpecDefault {
},
test("object") {
assertEncodesThenDecodes(schemaObject, Singleton)
},
test("all optional fields empty") {
assertEncodesThenDecodes(AllOptionalFields.schema, AllOptionalFields(None, None, None))
}
),
suite("record")(
Expand Down Expand Up @@ -1854,4 +1857,14 @@ object JsonCodecSpec extends ZIOSpecDefault {
implicit lazy val mapSchema: Schema[Map[KeyWrapper, ValueWrapper]] = Schema.map[KeyWrapper, ValueWrapper]
implicit lazy val schema: Schema[MapOfComplexKeysAndValues] = DeriveSchema.gen[MapOfComplexKeysAndValues]
}

final case class AllOptionalFields(
name: Option[String],
mode: Option[Int],
active: Option[Boolean]
)

object AllOptionalFields {
implicit lazy val schema: Schema[AllOptionalFields] = DeriveSchema.gen[AllOptionalFields]
}
}

0 comments on commit e24f38a

Please sign in to comment.