For JAX-RS endpoints with optional query params wi...
# server
n
For JAX-RS endpoints with optional query params with default values, I currently use
fun hello(@QueryParam("greeting") @DefaultValue("hi") greeting: String = "hi")
to get the same default value when called via REST or directly. Is there a way to avoid duplicating the default value?
a
You can declare the default value in a
const val
and then use it in both expressions.
Copy code
const val HELLO_GREETING_DEF = "hi"

hello(@QueryParam("greeting") @DefaultValue(HELLO_GREETING_DEF) greeting: String = HELLO_GREETING_DEF)