You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2020/02/06 12:58:29 UTC
[GitHub] [ignite] alex-plekhanov commented on a change in pull request
#7320: IGNITE-12468 Java thin client: deserialization of arrays,
collections and maps fixed
alex-plekhanov 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_r375818581
##########
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:
Information about user type is already lost when marshalling/unmarshalling client request on server side (IGNITE-12625).
For thick client we have the same behaviour:
```
ignite.getOrCreateCache(DEFAULT_CACHE_NAME).put(1, new Person[] {new Person(1, "name")});
Object obj = ignite.getOrCreateCache(DEFAULT_CACHE_NAME).get(1);
System.out.println(obj.getClass().getName()); // [Ljava.lang.Object
```
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services