In my REST API which is developed using Spring Framework, I have one Rest end point which receive Two Double values, the Rest Call is: http://localhost:8080/restapp/events/nearby/12.910967/77.599570
here, first parameter (double datatype) i.e 12.910967 i'm able receive correctly i.e, 12.910967. But second parameter i.e, 77.599570 i'm able receive only 77.0 the data after decimal point truncating.
my REST Backend is:
@RequestMapping(value = "/nearby/{lat}/{lngi}", method = RequestMethod.GET, produces = "application/json")
public List<Event> getNearByEvents(@PathVariable("lat") Double lat, @PathVariable("lngi") Double lngi, HttpServletResponse response) throws IOException
how receive double data type in REST api?
Altogether, the most common way is to use @ExceptionHandler on methods of @ControllerAdvice classes so that the exception handling will be applied globally or to a subset of controllers. ControllerAdvice is an annotation introduced in Spring 3.2, and as the name suggests, is “Advice” for multiple controllers.
Return 405 (Method Not Allowed), unless you want to replace every resource in the entire collection of resource - use with caution. 404 (Not Found) - if id not found or invalid and creating new resource is not allowed. Return 405 (Method Not Allowed), unless you want to modify the collection itself..
The most basic way of returning an error message from a REST API is to use the @ResponseStatus annotation. We can add the error message in the annotation's reason field. Although we can only return a generic error message, we can specify exception-specific error messages.
Update your code as below - Note the {lngi:.+}
which specifies a regex meaning some characters will appear post .
@RequestMapping(value = "/nearby/{lat}/{lngi:.+}", method = RequestMethod.GET, produces = "application/json")
public List<Event> getNearByEvents(@PathVariable("lat") Double lat, @PathVariable("lngi") Double lngi, HttpServletResponse response) throws IOException
I think this may be the same problem as is described here:
What was reported there was that something was attempting to apply suffix matching to the incoming URL ... and that was consuming everything after the first dot in the final path component.
In fact, this behaviour was deemed to be a bug, and was fixed in Spring 3.1:
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