can we give @QueryParam of type boolean a default value null ? if yes, how do we do it?
this is how I tried to do it but I still get false as default value:
@POST
public String setMethod(
@QueryParam("value1") @DefaultValue("null") Boolean value1)
I am facing the same problem, and unfortunately there isn't a direct way to solve this.
Sadly, we can't use enums because @RequestParam defaultValue
and switch-case need a constant. It also can't automatically map it from "null" into the enum.
@POST
public String setMethod(
@QueryParam("value1") @DefaultValue("null") String value1)
Boolean boolValue1 = null;
switch(value1) {
case "true":
boolValue1 = Boolean.TRUE;
break;
case "false":
boolValue1 = Boolean.FALSE;
break;
default:
break;
}
Since there isn't a case for null
, it should remain null.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With