7

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?

Raj
  • 739
  • 1
  • 10
  • 23

3 Answers3

3

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
Bond - Java Bond
  • 3,972
  • 6
  • 36
  • 59
1

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:

Community
  • 1
  • 1
Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
0

You can try forcing the entire value with regex in your RequestMapping value:

@RequestMapping(value = "/nearby/{lat}/{lngi:\d+\.\d+}")
Fritz Duchardt
  • 11,026
  • 4
  • 41
  • 60