This is an automated email from the ASF dual-hosted git repository.

mibo 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 7a50c58bf [OLINGO-1609] Fix issue in JSON deserializer
7a50c58bf is described below

commit 7a50c58bf300ce387078fc18ce3381985aa79770
Author: Scraylex <[email protected]>
AuthorDate: Thu Jul 6 16:42:59 2023 +0200

    [OLINGO-1609] Fix issue in JSON deserializer
    
    fix issue with multiple stream properties and metadata=full for 
deserialization
---
 .../core/serialization/JsonEntityDeserializer.java |  3 ++
 .../olingo/client/core/JsonDeserializerTest.java   | 60 ++++++++++++++++++++++
 .../org/apache/olingo/client/core/Employee.json    | 19 +++++++
 3 files changed, 82 insertions(+)

diff --git 
a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/JsonEntityDeserializer.java
 
b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/JsonEntityDeserializer.java
index b77840756..4d0e7c3cd 100644
--- 
a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/JsonEntityDeserializer.java
+++ 
b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/JsonEntityDeserializer.java
@@ -226,6 +226,9 @@ public class JsonEntityDeserializer extends 
JsonDeserializer {
           toRemove.add(link.getTitle() + "@" + annotation.getTerm());
         }
       }
+      if (tree.get(link.getTitle() + Constants.JSON_TYPE) != null) {
+        toRemove.add(link.getTitle() + Constants.JSON_TYPE);
+      }
     }
 
     tree.remove(toRemove);
diff --git 
a/lib/client-core/src/test/java/org/apache/olingo/client/core/JsonDeserializerTest.java
 
b/lib/client-core/src/test/java/org/apache/olingo/client/core/JsonDeserializerTest.java
new file mode 100644
index 000000000..023f9ce24
--- /dev/null
+++ 
b/lib/client-core/src/test/java/org/apache/olingo/client/core/JsonDeserializerTest.java
@@ -0,0 +1,60 @@
+/*
+ * 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.
+ */
+package org.apache.olingo.client.core;
+
+import org.apache.olingo.client.api.data.ResWrap;
+import org.apache.olingo.client.api.domain.ClientEntity;
+import org.apache.olingo.client.api.domain.ClientLink;
+import org.apache.olingo.client.api.serialization.ODataDeserializerException;
+import org.apache.olingo.client.core.serialization.ClientODataDeserializerImpl;
+import org.apache.olingo.client.core.serialization.ODataBinderImpl;
+import org.apache.olingo.commons.api.data.Entity;
+import org.apache.olingo.commons.api.format.ContentType;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+
+public class JsonDeserializerTest {
+
+
+    /**
+     * Without the attached fix this test with the corresponding resource json 
will throw a {@link java.lang.IllegalArgumentException}
+     * with the message: 'Cannot build a primitive value for Stream'
+     *
+     * this is because the <streamproptitle>@odata.type key is incorrectly 
filtered by the previous implementation
+     */
+    @Test
+    public void testDeserializationStreamProperties() throws 
ODataDeserializerException {
+        try (InputStream inputStream = 
getClass().getResourceAsStream("Employee.json")) {
+            ClientODataDeserializerImpl clientODataDeserializer =
+                new ClientODataDeserializerImpl(false, 
ContentType.JSON_FULL_METADATA);
+            ResWrap<Entity> entity = 
clientODataDeserializer.toEntity(inputStream);
+            ODataBinderImpl oDataBinder = new 
ODataBinderImpl(ODataClientFactory.getClient());
+            ClientEntity oDataEntity = oDataBinder.getODataEntity(entity);
+            List<ClientLink> mediaEditLinks = oDataEntity.getMediaEditLinks();
+            assertEquals(2, mediaEditLinks.size());
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+    }
+}
diff --git 
a/lib/client-core/src/test/resources/org/apache/olingo/client/core/Employee.json
 
b/lib/client-core/src/test/resources/org/apache/olingo/client/core/Employee.json
new file mode 100644
index 000000000..c4cf6b5d9
--- /dev/null
+++ 
b/lib/client-core/src/test/resources/org/apache/olingo/client/core/Employee.json
@@ -0,0 +1,19 @@
+{
+  "@odata.context": 
"http://odatae2etest.azurewebsites.net/javatest/DefaultService/$metadata#Employees/$entity";,
+  "@odata.etag": 
"W/\"f557984846c2e312e155c9e8bede6186c4be9094b4edec2f5f32fe2a813f0cf1\"",
+  "@odata.id": 
"http://odatae2etest.azurewebsites.net/javatest/DefaultService/Employees(1)",
+  "[email protected]": "#Int64",
+  "Id": 1,
+  "FirstName": "Paul",
+  "LastName": "Mayor",
+  "[email protected]": "#Date",
+  "DateOfBirth": "1973-08-17",
+  "[email protected]": "#Stream",
+  "[email protected]": 
"W/\"32d1efc04f8aa14e828fa67d5161fa3664366e089b187402732a7c054ea2bc26\"",
+  "[email protected]": "image/jpeg",
+  "[email protected]": 
"http://odatae2etest.azurewebsites.net/javatest/DefaultService/Employees(1)/Picture",
+  "[email protected]": "#Stream",
+  "[email protected]": 
"W/\"7234c31b74af36899934883c9ff09ab0c70f8d0efdab9ac1a90010074f812931\"",
+  "[email protected]": "image/jpeg",
+  "[email protected]": 
"http://odatae2etest.azurewebsites.net/javatest/DefaultService/Employees(1)/Thumbnail"
+}
\ No newline at end of file

Reply via email to