You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by ra...@apache.org on 2021/03/19 09:51:01 UTC
[olingo-odata4] branch master updated: [OLINGO-1062]Fix
deserialization of empty collections
This is an automated email from the ASF dual-hosted git repository.
ramyav pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/olingo-odata4.git
The following commit(s) were added to refs/heads/master by this push:
new 47a6775 [OLINGO-1062]Fix deserialization of empty collections
47a6775 is described below
commit 47a6775c7eed3e35f0a451872163cc99e000beae
Author: ramya vasanth <ra...@sap.com>
AuthorDate: Fri Mar 19 15:20:52 2021 +0530
[OLINGO-1062]Fix deserialization of empty collections
---
.../annotation/ClientCsdlDynamicExpression.java | 3 ++
.../apache/olingo/client/core/MetadataTest.java | 24 +++++++++++
.../client/core/empty-collection-metadata.xml | 46 ++++++++++++++++++++++
3 files changed, 73 insertions(+)
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/ClientCsdlDynamicExpression.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/ClientCsdlDynamicExpression.java
index 1afbca5..fcbded1 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/ClientCsdlDynamicExpression.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/ClientCsdlDynamicExpression.java
@@ -131,6 +131,9 @@ public abstract class ClientCsdlDynamicExpression extends CsdlDynamicExpression
} else if (COLLECTION.equals(jp.getCurrentName())) {
jp.nextToken();
expression = jp.readValueAs(ClientCsdlCollection.class);
+ if(expression == null) {
+ expression = new ClientCsdlCollection();
+ }
} else if (IF.equals(jp.getCurrentName())) {
jp.nextToken();
jp.nextToken();
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/MetadataTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/MetadataTest.java
index 72dcf4f..099b3dc 100644
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/MetadataTest.java
+++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/MetadataTest.java
@@ -77,6 +77,7 @@ import org.apache.olingo.commons.api.edm.provider.annotation.CsdlExpression;
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlLogicalOrComparisonExpression.LogicalOrComparisonExpressionType;
//CHECKSTYLE:ON
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlPath;
+import org.apache.olingo.commons.api.edm.provider.annotation.CsdlPropertyValue;
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlRecord;
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlUrlRef;
import org.apache.olingo.commons.api.format.ContentType;
@@ -1213,4 +1214,27 @@ public class MetadataTest extends AbstractTest {
annotation = annotations.getAnnotation(term, null);
assertNotNull(annotation);
}
+
+ @Test
+ public void metadataWithEmptyCollection() throws Exception {
+ InputStream input = getClass().getResourceAsStream("empty-collection-metadata.xml");
+ final XMLMetadata metadata = client.getDeserializer(ContentType.APPLICATION_XML).toMetadata(input);
+
+ CsdlSchema schema = metadata.getSchema("Foo");
+ assertNotNull(schema);
+
+ CsdlAnnotations annotations = schema.getAnnotationGroup("Foo.EntityContainer/Bar", null);
+ assertNotNull(annotations);
+
+ CsdlAnnotation annotation = annotations.getAnnotation("Capabilities.FilterRestrictions");
+ assertNotNull(annotation);
+
+ CsdlPropertyValue value = annotation.getExpression()
+ .asDynamic().asRecord().getPropertyValues().get(0);
+ assertNotNull(value);
+
+ CsdlExpression collection = value.getValue();
+ assertNotNull(value);
+ assertEquals(new CsdlCollection(), collection);
+ }
}
diff --git a/lib/client-core/src/test/resources/org/apache/olingo/client/core/empty-collection-metadata.xml b/lib/client-core/src/test/resources/org/apache/olingo/client/core/empty-collection-metadata.xml
new file mode 100644
index 0000000..e6d21de
--- /dev/null
+++ b/lib/client-core/src/test/resources/org/apache/olingo/client/core/empty-collection-metadata.xml
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<edmx:Edmx Version="4.0" xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx">
+ <edmx:Reference Uri="https://oasis-tcs.github.io/odata-vocabularies/vocabularies/Org.OData.Capabilities.V1.xml">
+ <edmx:Include Alias="Capabilities" Namespace="Org.OData.Capabilities.V1"/>
+ </edmx:Reference>
+ <edmx:DataServices>
+ <Schema Namespace="Foo" xmlns="http://docs.oasis-open.org/odata/ns/edm">
+ <EntityContainer Name="EntityContainer">
+ <EntitySet Name="Bar" EntityType="Foo.Bar"/>
+ </EntityContainer>
+ <EntityType Name="Bar">
+ <Key>
+ <PropertyRef Name="ID"/>
+ </Key>
+ <Property Name="ID" Type="Edm.Guid" Nullable="false"/>
+ </EntityType>
+ <Annotations Target="Foo.EntityContainer/Bar">
+ <Annotation Term="Capabilities.FilterRestrictions">
+ <Record Type="Capabilities.FilterRestrictionsType">
+ <PropertyValue Property="NonFilterableProperties">
+ <Collection/>
+ </PropertyValue>
+ </Record>
+ </Annotation>
+ </Annotations>
+ </Schema>
+ </edmx:DataServices>
+</edmx:Edmx>