You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@olingo.apache.org by "Vladislav Glinskiy (Jira)" <ji...@apache.org> on 2019/09/09 09:29:00 UTC

[jira] [Commented] (OLINGO-1392) Olingo V4 client reports invalid value type for `Edm.GeometryCollection` and `Edm.GeographyCollection` JSON values

    [ https://issues.apache.org/jira/browse/OLINGO-1392?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16925515#comment-16925515 ] 

Vladislav Glinskiy commented on OLINGO-1392:
--------------------------------------------

Including type control Information(`@odata.type`) resolves the issue:

 
{code:java}
{
  "GeometryCollectionField@odata.type":"#GeometryCollection",
  "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"
      }
    }
  }
}
{code}
 

> Olingo V4 client reports invalid value type for `Edm.GeometryCollection` and `Edm.GeographyCollection` JSON values
> ------------------------------------------------------------------------------------------------------------------
>
>                 Key: OLINGO-1392
>                 URL: https://issues.apache.org/jira/browse/OLINGO-1392
>             Project: Olingo
>          Issue Type: Bug
>          Components: odata4-client
>            Reporter: Vladislav Glinskiy
>            Priority: Major
>             Fix For: (Java) V4 4.7.0
>
>
> 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|https://github.com/apache/olingo-odata4/blob/master/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/JsonDeserializer.java#L64] which does not work correctly with values of `Edm.GeometryCollection` and `Edm.GeographyCollection` OData types, such as:
> {code:java}
> {
>   "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"
>       }
>     }
>   }
> }
> {code}
> [I created a unit test to reproduce the issue|https://github.com/vladglinskiy/olingo-odata4/commit/4613e2a4f266bf99f56dd4cac2d58df0c03efa1d#diff-c2bf3c9859b1f7113d0296bc1b6dcb5dR58]:
> {code:java}
>   @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);
>   }
> {code}
> Please, note that the deserializer works fine for GeometryPoint type. [toEntityWithPointField test|https://github.com/vladglinskiy/olingo-odata4/commit/4613e2a4f266bf99f56dd4cac2d58df0c03efa1d#diff-c2bf3c9859b1f7113d0296bc1b6dcb5dR35] 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:
> {code:java}
> -------------------------------------------------------
>  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>
> {code}



--
This message was sent by Atlassian Jira
(v8.3.2#803003)