Skip to content

Commit

Permalink
lwcapi: fix npe when samples missing (#1731)
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 authored Nov 21, 2024
1 parent 57369c1 commit 5c8957f
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 5c8957f

Please sign in to comment.