Uploaded image for project: 'Olingo'
  1. Olingo
  2. OLINGO-1392

Olingo V4 client reports invalid value type for `Edm.GeometryCollection` and `Edm.GeographyCollection` JSON values

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Not A Problem
    • None
    • (Java) V4 4.7.0
    • odata4-client
    • None

    Description

      Olingo V4 client reports value type for `Edm.GeometryCollection` and `Edm.GeographyCollection` OData types as `ValueType.COMPLEX` instead of expected `ValueType.GEOSPATIAL`.

      Debugging shows that the client uses JsonDeserializer which does not work correctly with values of `Edm.GeometryCollection` and `Edm.GeographyCollection` OData types, such as:

      {
        "GeometryCollectionField":{
          "type":"GeometryCollection",
          "geometries":[
            {
              "type":"Point",
              "coordinates":[
                1.0,
                1.0
              ],
              "crs":{
                "type":"name",
                "properties":{
                  "name":"EPSG:4326"
                }
              }
            }
          ],
          "crs":{
            "type":"name",
            "properties":{
              "name":"EPSG:4326"
            }
          }
        }
      }
      

      I created a unit test to reproduce the issue:

        @Test
        public void toEntityWithGeometryCollectionField() throws Exception {
      
          GeospatialCollection collection = new GeospatialCollection(Geospatial.Dimension.GEOMETRY, SRID.valueOf("4326"),
                                                                     Collections.<Geospatial>singletonList(POINT));
          ByteArrayOutputStream output = new ByteArrayOutputStream();
          OutputStreamWriter writer = new OutputStreamWriter(output, Constants.UTF8);
      
          Entity entity = new Entity();
          final Property propertyResource = new Property();
          propertyResource.setName("GeometryCollectionField");
          propertyResource.setValue(ValueType.GEOSPATIAL, collection);
          entity.getProperties().add(propertyResource);
      
          SERIALIZER.write(writer, new ResWrap(null, null, entity));
          System.out.println(new String(output.toByteArray()));
      
          ResWrap<Entity> entityResWrap = DESERIALIZER.toEntity(new ByteArrayInputStream(output.toByteArray()));
          Property geometryCollection = entityResWrap.getPayload().getProperty("GeometryCollectionField");
          Assert.assertNotNull(geometryCollection);
      
          ValueType actualValueType = geometryCollection.getValueType();
          Assert.assertEquals("Unexpected GeospatialCollection type", ValueType.GEOSPATIAL, actualValueType);
          Assert.assertTrue(geometryCollection.asGeospatial() instanceof GeospatialCollection);
        }
      

      Please, note that the deserializer works fine for GeometryPoint type. toEntityWithPointField test demonstrates that.

      Steps to reproduce:
      1. git clone https://github.com/vladglinskiy/olingo-odata4.git
      2. mvn clean test -pl lib/client-core/ -Dtest=JsonDeserializerTest

      the test will fail with the following error:

      -------------------------------------------------------
       T E S T S
      -------------------------------------------------------
      Running org.apache.olingo.client.core.serialization.JsonDeserializerTest
      Tests run: 2, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.214 sec <<< FAILURE! - in org.apache.olingo.client.core.serialization.JsonDeserializerTest
      toEntityWithGeometryCollectionField(org.apache.olingo.client.core.serialization.JsonDeserializerTest)  Time elapsed: 0.181 sec  <<< FAILURE!
      java.lang.AssertionError: Unexpected GeospatialCollection type expected:<GEOSPATIAL> but was:<COMPLEX>
      	at org.junit.Assert.fail(Assert.java:88)
      	at org.junit.Assert.failNotEquals(Assert.java:743)
      	at org.junit.Assert.assertEquals(Assert.java:118)
      	at org.apache.olingo.client.core.serialization.JsonDeserializerTest.toEntityWithGeometryCollectionField(JsonDeserializerTest.java:104)
      
      
      Results :
      
      Failed tests: 
        JsonDeserializerTest.toEntityWithGeometryCollectionField:104 Unexpected GeospatialCollection type expected:<GEOSPATIAL> but was:<COMPLEX>
      
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            vladglinskiy Vladislav Glinskiy
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: