Skip to content

Commit

Permalink
lwcapi: fix npe when samples missing
Browse files Browse the repository at this point in the history
If the payload didn't include a samples key, then it would
get set to `null` and result in errors. Default to an empty
list.
  • Loading branch information
brharrington committed Nov 21, 2024
1 parent 57369c1 commit 1aa9a40
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ object EvaluateApi {
id: String,
@JsonDeserialize(`using` = classOf[SortedTagMapDeserializer]) tags: SortedTagMap,
value: Double,
samples: List[List[Any]]
samples: List[List[Any]] = Nil
)

case class EvaluateRequest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,10 @@ class EvaluateApiSuite extends MUnitRouteSuite {
assertEquals(response.status, StatusCodes.OK)
}
}

test("item samples decode") {
val json = """{"id":"1","tags":{"name":"test"},"value":1.0}"""
val expected = EvaluateApi.Item("1", SortedTagMap("name" -> "test"), 1.0, Nil)
assertEquals(Json.decode[EvaluateApi.Item](json), expected)
}
}

0 comments on commit 1aa9a40

Please sign in to comment.