diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java index ea3cdf46b..08f92639d 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java @@ -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 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); diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerEntityTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerEntityTest.java index 9de9b1039..a6f380ae2 100644 --- a/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerEntityTest.java +++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerEntityTest.java @@ -1046,6 +1046,14 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe entityType); 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, @@ -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