pavlukhin commented on a change in pull request #7320: IGNITE-12468 Java thin 
client: deserialization of arrays, collections and maps fixed
URL: https://github.com/apache/ignite/pull/7320#discussion_r375830252
 
 

 ##########
 File path: 
modules/core/src/main/java/org/apache/ignite/internal/client/thin/ClientUtils.java
 ##########
 @@ -522,12 +528,73 @@ void writeObject(BinaryOutputStream out, Object obj) {
 
     /** Read Ignite binary object from input stream. */
     <T> T readObject(BinaryInputStream in, boolean keepBinary) {
-        Object val = marsh.unmarshal(in);
+        if (keepBinary)
+            return (T)marsh.unmarshal(in);
+        else {
+            BinaryReaderHandles hnds = new BinaryReaderHandles();
+
+            return (T)unwrapBinary(marsh.deserialize(in, hnds), hnds);
+        }
+    }
+
+    /**
+     * Unwrap binary object.
+     */
+    private Object unwrapBinary(Object obj, BinaryReaderHandles hnds) {
+        if (obj instanceof BinaryObjectImpl) {
+            BinaryObjectImpl obj0 = (BinaryObjectImpl)obj;
+
+            return 
marsh.deserialize(BinaryHeapInputStream.create(obj0.array(), obj0.start()), 
hnds);
+        }
+        else if (obj instanceof BinaryObject )
+            return ((BinaryObject)obj).deserialize();
+        else if (BinaryUtils.knownCollection(obj))
+            return unwrapCollection((Collection<Objects>)obj, hnds);
+        else if (BinaryUtils.knownMap(obj))
+            return unwrapMap((Map<Object, Object>)obj, hnds);
+        else if (obj instanceof Object[])
+            return unwrapArray((Object[])obj, hnds);
+        else
+            return obj;
+    }
+
+    /**
+     * Unwrap collection with binary objects.
+     */
+    private Collection<Object> unwrapCollection(Collection<Objects> col, 
BinaryReaderHandles hnds) {
+        Collection<Object> col0 = BinaryUtils.newKnownCollection(col);
+
+        for (Object obj0 : col)
+            col0.add(unwrapBinary(obj0, hnds));
+
+        return (col0 instanceof MutableSingletonList) ? 
U.convertToSingletonList(col0) : col0;
+    }
+
+    /**
+     * Unwrap map with binary objects.
+     */
+    private Map<Object, Object> unwrapMap(Map<Object, Object> map, 
BinaryReaderHandles hnds) {
+        Map<Object, Object> map0 = BinaryUtils.newMap(map);
+
+        for (Map.Entry<Object, Object> e : map.entrySet())
+            map0.put(unwrapBinary(e.getKey(), hnds), 
unwrapBinary(e.getValue(), hnds));
+
+        return map0;
+    }
+
+    /**
+     * Unwrap array with binary objects.
+     */
+    private Object[] unwrapArray(Object[] arr, BinaryReaderHandles hnds) {
+        if (BinaryUtils.knownArray(arr))
+            return arr;
+
+        Object[] res = new Object[arr.length];
 
 Review comment:
   Got it.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to