MrNiamh
03/09/2024, 4:03 PMMrNiamh
03/09/2024, 4:03 PMval lens = Jackson.autoBody<TestDTO>().toLens()
fun testEndpoint(): ContractRoute =
"/test" meta {
receiving(lens to TestDTO.example)
returning(Status.OK)
} bindContract Method.POST to
{ request: Request ->
val r = lens(request)
println(r.values.first().length)
Response(OK)
}
data class TestDTO(
val values: List<String>,
) {
companion object {
val example = TestDTO(
listOf("Hello"),
)
}
}
And you can curl it
curl -X 'POST' \
'<http://localhost:9000/test>' \
-H 'accept: */*' \
-H 'Content-Type: application/json' \
-d '{
"values": [
null
]
}'
You should 500
because it can't call .length
on a null stringdave
03/09/2024, 4:29 PMval a = ObjectMapper().registerModules(KotlinModule.Builder().build())
println(a.readValue("""{"values":["null"]}""", TestDTO::class.java))
dave
03/09/2024, 4:32 PMdave
03/09/2024, 4:32 PMMrNiamh
03/09/2024, 4:33 PMdave
03/09/2024, 4:37 PMdata class TestDTO(
val values: List<String>,
) {
init {
require(values.map { it!! }.isNotEmpty())
}
}
dave
03/09/2024, 4:37 PMdata class TestDTO(
val values: List<String>,
) {
init {
values.forEach { it!! }
}
}
MrNiamh
03/09/2024, 4:41 PMEmil Kantis
03/09/2024, 5:19 PM