[OLINGO-1471] Adding support for multiple interior rings
This commit is contained in:
parent
5ff6482ff0
commit
64b1a449de
|
@ -971,13 +971,14 @@ public class ODataJsonDeserializer implements ODataDeserializer {
|
|||
|
||||
private Polygon readGeoPolygon(final String name, final Geospatial.Dimension dimension, JsonNode node, SRID srid)
|
||||
throws DeserializerException, EdmPrimitiveTypeException {
|
||||
// GeoJSON would allow for more than one interior polygon (hole).
|
||||
// But there is no place in the data object to store this information so for now we throw an error.
|
||||
// There could be a more strict verification that the lines describe boundaries and have the correct winding order.
|
||||
if (node.isArray() && (node.size() == 1 || node.size() == 2)) {
|
||||
return new Polygon(dimension, srid,
|
||||
node.size() > 1 ? readGeoPointValues(name, dimension, 4, true, node.get(1)) : null,
|
||||
readGeoPointValues(name, dimension, 4, true, node.get(0)));
|
||||
if (node.isArray() && (node.size() >= 1)) {
|
||||
List<LineString> interiors = new ArrayList<>();
|
||||
for (int i = 1; i < node.size(); i++) {
|
||||
interiors.add(new LineString(dimension, srid, readGeoPointValues(name, dimension, 4, true, node.get(i))));
|
||||
}
|
||||
return new Polygon(dimension, srid, interiors,
|
||||
new LineString(dimension, srid, readGeoPointValues(name, dimension, 4, true, node.get(0))));
|
||||
}
|
||||
throw new DeserializerException("Invalid polygon values '" + node + "' in property: " + name,
|
||||
DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY, name);
|
||||
|
|
|
@ -1047,6 +1047,14 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
|
|||
polygon = (Polygon) entity.getProperties().get(0).getValue();
|
||||
assertEquals(0, polygon.getNumberOfInteriorRings());
|
||||
|
||||
entity = deserialize("{\"" + entityType.getPropertyNames().get(0) + "\":{"
|
||||
+ "\"type\":\"Polygon\",\"coordinates\":[[[0,0],[3,0],[3,3],[0,3],[0,0]],"
|
||||
+ "[[1,1],[1,2],[2,2],[2,1],[1,1]],"
|
||||
+ "[[1,1],[1,2],[2,2],[2,1],[1,1]]]}}",
|
||||
entityType);
|
||||
polygon = (Polygon) entity.getProperties().get(0).getValue();
|
||||
assertEquals(2, polygon.getNumberOfInteriorRings());
|
||||
|
||||
expectException("{\"" + entityType.getPropertyNames().get(0) + "\":{"
|
||||
+ "\"type\":\"Polygon\",\"coordinates\":{\"ext\":[[0,0],[3,0],[0,3],[0,0]]}}}", entityType,
|
||||
ContentType.JSON, DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY);
|
||||
|
@ -1056,11 +1064,6 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
|
|||
expectException("{\"" + entityType.getPropertyNames().get(0) + "\":{"
|
||||
+ "\"type\":\"Polygon\",\"coordinates\":[[[0,0],[3,0],[3,3],[0,3],[42,87]]]}}", entityType,
|
||||
ContentType.JSON, DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY);
|
||||
expectException("{\"" + entityType.getPropertyNames().get(0) + "\":{"
|
||||
+ "\"type\":\"Polygon\",\"coordinates\":[[[0,0],[3,0],[3,3],[0,3],[0,0]],"
|
||||
+ "[[1,1],[1,2],[2,2],[2,1],[1,1]],"
|
||||
+ "[[1,1],[1,2],[2,2],[2,1],[1,1]]]}}", entityType,
|
||||
ContentType.JSON, DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue