0

I created an endpoint, and I want to display a message if I don't fill a specific parameter.

For example:

 @NotNull(message = "The distance must be specified.") 
 @QueryParam("distance") 
 final double distance; 

But for some reason I don't receive anything if I don't fill the field. Maybe because this is not a String? How should I do?

2 Answers2

1

As double value can never be null, this never meets the criteria. If you try with a Wrapper class Double, then this should give your expected result.

@NotNull(message = "The distance must be specified.") 
@QueryParam("distance") 
final Double distance; 
SKumar
  • 1,940
  • 1
  • 7
  • 12
0

double will always evaluate to 0 in case it doesn't exist, that's why @NotNull is not throwing an exception.

Use Double then if you don't send it, it will null.

Eklavya
  • 17,618
  • 4
  • 28
  • 57