I’m trying to add a nullable `@RequestParam` of ty...
# spring
o
I’m trying to add a nullable
@RequestParam
of type
Int
, but get
Copy code
"Optional int parameter 'p' is present but cannot be translated into a null value due to being declared as a primitive type. Consider declaring it as object wrapper for the corresponding primitive type."
Any way I can force Kotlin to use the wrapper class Integer instead of the primitive type?
c
if it's optional it should be
Int?
👍 2
o
Yeah, that works. I tried having a default value for it
But changed to elvis operator now
Thanks!
simple smile 1
c
here problem is that if you mark @RequestParam as optional Spring will pass null, so default value is ignored. You can have it as
Int
to avoid elvis, but instead of Kotlin default value you have to use
@RequestParam(name="blabla", required=false, defaultValue="yourDefault")
👍 1
o
Cool, thanks 🙂
simple smile 1
340 Views