Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,9 @@ private[smithy4s] class SchemaVisitorJCodec(
def expecting: String = "localDate"

def decodeValue(cursor: Cursor, in: JsonReader): LocalDate =
LocalDate.parseUnsafe(in.readString(null))
LocalDate
.parse(in.readString(null))
.getOrElse(in.decodeError("expected " + expecting))

def encodeValue(x: LocalDate, out: JsonWriter): Unit =
out.writeNonEscapedAsciiVal(x.toString())
Expand Down
11 changes: 11 additions & 0 deletions modules/json/test/src/smithy4s/json/SchemaVisitorJCodecTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,17 @@ class SchemaVisitorJCodecTests() extends FunSuite {

}

test("throw PayloadError for invalid local date") {
try {
implicit val schema: Schema[LocalDate] = localdate

readFromString[LocalDate]("\"2026-33-12\"")
fail("Unexpected success")
} catch {
case PayloadError(_, expected, _) => expect.same(expected, "localDate")
}
}

test("Optional encode from present value") {
val foo = Foo(1, Some(2))
val json = """{"a":1,"_b":2}"""
Expand Down