-
Notifications
You must be signed in to change notification settings - Fork 376
/
APIRequestSingleCoordinateConverter.java
42 lines (36 loc) 路 1.94 KB
/
APIRequestSingleCoordinateConverter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
* This file is part of Openrouteservice.
*
* Openrouteservice is free software; you can redistribute it and/or modify it under the terms of the
* GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this library;
* if not, see <https://www.gnu.org/licenses/>.
*/
package org.heigit.ors.api.converters;
import org.locationtech.jts.geom.Coordinate;
import org.springframework.core.convert.converter.Converter;
public class APIRequestSingleCoordinateConverter implements Converter<String, Coordinate> {
@Override
public Coordinate convert(String coordinatePair) {
Coordinate coordinate;
String[] coordValues = coordinatePair.split(",");
if (coordValues.length == 2) {
coordinate = new Coordinate();
coordinate.x = Double.parseDouble(coordValues[0]);
coordinate.y = Double.parseDouble(coordValues[1]);
return coordinate;
}
// This is a workaround for the breaking change: https://github.com/spring-projects/spring-framework/issues/26679
// This is fixed with a "missingAfterConversion" flag in spring-boot 3.x.x.
// Required parameters raised a HttpMessageConversionException before spring 2.7.x. when present but wrong.
// With spring boot 2.7.x it raises a MissingServletRequestParameterException.
// By throwing a RuntimeException in the custom converter spring itself now raises a HttpMessageConversionException.
throw new IllegalArgumentException("could not parse coordinates");
}
}