I'm developing my first REST API using Spring boot.
I created multiple requests on my API and I'm currently testing them.
I found a bug in one of these requests :
When the @PathVariable
is set it's rounded
Here is the code :
@RequestMapping(path = "/find/near/{lati}/{longi}", method = GET, produces = APPLICATION_JSON_VALUE)
public Animals getAnimalsNearPosition(@PathVariable double lati, @PathVariable double longi) throws CenterNotFoundException {
// On récupère le centre associé à cette cage
Center center = centers.findCenterNear(lati, longi);
Animals animals = new Animals();
// On recherche parmis toutes les cages celles ayant une position proche
for (Cage c : center.getCages()) {
if (Position.isNear(c.getPosition().getLatitude(), lati, c.getPosition().getLongitude(), longi)) {
for (Animal a : c.getResidents()) {
animals.addAnimal(a);
}
}
}
// On retourne les animaux
return animals;
}
For instance if I send
GET /find/near/4.50/1.39
the variable lati is equals to 4.50 but longi is equal to 1.0 and not 1.39.
I tried to debug using Intellij but I can't figure why it happens...
Any idea ?