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/04/09 09:50:00 UTC

[GitHub] [ignite] xtern opened a new pull request #7648: IGNITE-12857 Put custom objects via REST

xtern opened a new pull request #7648: IGNITE-12857 Put custom objects via REST
URL: https://github.com/apache/ignite/pull/7648
 
 
   

----------------------------------------------------------------
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

[GitHub] [ignite] xtern commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST

Posted by GitBox <gi...@apache.org>.
xtern commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST
URL: https://github.com/apache/ignite/pull/7648#discussion_r409839167
 
 

 ##########
 File path: modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/IgniteBinaryObjectJsonDeserializer.java
 ##########
 @@ -0,0 +1,343 @@
+/*
+ * 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.ignite.internal.processors.rest.protocols.http.jetty;
+
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.ObjectCodec;
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.JsonDeserializer;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.JsonNodeType;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.binary.BinaryObjectBuilder;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryType;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.binary.BinaryClassDescriptor;
+import org.apache.ignite.internal.binary.BinaryFieldMetadata;
+import org.apache.ignite.internal.binary.BinaryObjectImpl;
+import org.apache.ignite.internal.binary.BinaryTypeImpl;
+import org.apache.ignite.internal.binary.BinaryUtils;
+import org.apache.ignite.internal.binary.GridBinaryMarshaller;
+import org.apache.ignite.internal.processors.cache.GridCacheUtils;
+import org.apache.ignite.internal.processors.query.QueryTypeDescriptorImpl;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * JSON deserializer into the Ignite binary object.
+ */
+public class IgniteBinaryObjectJsonDeserializer extends JsonDeserializer {
 
 Review comment:
   Fixed

----------------------------------------------------------------
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

[GitHub] [ignite] alex-plekhanov commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST

Posted by GitBox <gi...@apache.org>.
alex-plekhanov commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST
URL: https://github.com/apache/ignite/pull/7648#discussion_r409529041
 
 

 ##########
 File path: modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
 ##########
 @@ -157,16 +160,15 @@
      *
      * @param hnd Handler.
      * @param authChecker Authentication checking closure.
-     * @param log Logger.
+     * @param ctx Kernal context.
      */
-    GridJettyRestHandler(GridRestProtocolHandler hnd, IgniteClosure<String, Boolean> authChecker, IgniteLogger log) {
+    GridJettyRestHandler(GridRestProtocolHandler hnd, IgniteClosure<String, Boolean> authChecker, GridKernalContext ctx) {
         assert hnd != null;
-        assert log != null;
 
 Review comment:
   Let's keep this assert (ctx != null)

----------------------------------------------------------------
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

[GitHub] [ignite] xtern commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST

Posted by GitBox <gi...@apache.org>.
xtern commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST
URL: https://github.com/apache/ignite/pull/7648#discussion_r409839270
 
 

 ##########
 File path: modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java
 ##########
 @@ -2878,6 +3134,341 @@ public void ref(CircularRef ref) {
         }
     }
 
+    /** */
+    @JsonInclude(JsonInclude.Include.NON_NULL)
+    @SuppressWarnings("AssignmentOrReturnOfFieldWithMutableType")
+    public static class OuterClass {
+        /** */
+        private long id;
+
+        /** */
+        private String name;
+
+        /** */
+        private double doubleVal;
+
+        /** */
+        private Boolean optional;
+
+        /** */
+        private ArrayList<Integer> list;
+
+        /** */
+        private Timestamp timestamp;
+
+        /** */
+        private long[] longs;
+
+        /** */
+        OuterClass() {
+            // No-op.
+        }
+
+        /** */
+        OuterClass(long id, String name, double doubleVal, List<Integer> list, @Nullable Boolean optional) {
+            this.id = id;
+            this.name = name;
+            this.doubleVal = doubleVal;
+            this.list = new ArrayList<>(list);
+            this.optional = optional;
+        }
+
+        /** */
+        public long getId() {
+            return id;
+        }
+
+        /** */
+        public String getName() {
+            return name;
+        }
+
+        /** */
+        public Boolean getOptional() {
+            return optional;
+        }
+
+        /** */
+        public double getDoubleVal() {
+            return doubleVal;
+        }
+
+        /** */
+        public ArrayList<Integer> getList() {
+            return list;
+        }
+
+        /** */
+        public Timestamp getTimestamp() {
+            return timestamp;
+        }
+
+        /** */
+        public long[] getLongs() {
+            return longs;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean equals(Object o) {
+            if (this == o)
+                return true;
+            if (o == null || getClass() != o.getClass())
+                return false;
+            OuterClass aClass = (OuterClass)o;
+            return id == aClass.id &&
+                Double.compare(aClass.doubleVal, doubleVal) == 0 &&
+                Objects.equals(name, aClass.name) &&
+                Objects.equals(optional, aClass.optional) &&
+                Objects.equals(list, aClass.list) &&
+                Objects.equals(timestamp, aClass.timestamp) &&
+                Arrays.equals(longs, aClass.longs);
+        }
+
+        /** {@inheritDoc} */
+        @Override public int hashCode() {
+            return Objects.hash(id, name, optional, doubleVal, list, timestamp, longs);
+        }
+
+        /** {@inheritDoc} */
+        @Override public String toString() {
+            return "OuterClass{" +
+                "id=" + id +
+                ", name='" + name + '\'' +
+                ", doubleVal=" + doubleVal +
+                ", optional=" + optional +
+                ", list=" + list +
+                ", timestamp=" + timestamp +
+                ", bytes=" + Arrays.toString(longs) +
+                '}';
+        }
+    }
+
+    /** */
+    public enum COLOR {
 
 Review comment:
   Fixed

----------------------------------------------------------------
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

[GitHub] [ignite] NSAmelchev commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST

Posted by GitBox <gi...@apache.org>.
NSAmelchev commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST
URL: https://github.com/apache/ignite/pull/7648#discussion_r409866685
 
 

 ##########
 File path: modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/IgniteBinaryObjectJsonDeserializer.java
 ##########
 @@ -0,0 +1,342 @@
+/*
+ * 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.ignite.internal.processors.rest.protocols.http.jetty;
+
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.ObjectCodec;
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.JsonDeserializer;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.JsonNodeType;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.binary.BinaryObjectBuilder;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryType;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.binary.BinaryClassDescriptor;
+import org.apache.ignite.internal.binary.BinaryFieldMetadata;
+import org.apache.ignite.internal.binary.BinaryObjectImpl;
+import org.apache.ignite.internal.binary.BinaryTypeImpl;
+import org.apache.ignite.internal.binary.BinaryUtils;
+import org.apache.ignite.internal.binary.GridBinaryMarshaller;
+import org.apache.ignite.internal.processors.query.QueryTypeDescriptorImpl;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * JSON deserializer into the Ignite binary object.
+ */
+public class IgniteBinaryObjectJsonDeserializer extends JsonDeserializer<BinaryObjectImpl> {
+    /** Property name to set binary type name. */
+    public static final String BINARY_TYPE_PROPERTY = "binaryTypeName";
+
+    /** Property name to set cache name. */
+    public static final String CACHE_NAME_PROPERTY = "cacheName";
+
+    /** Kernal context. */
+    private final GridKernalContext ctx;
+
+    /**
+     * @param ctx Kernal context.
+     */
+    public IgniteBinaryObjectJsonDeserializer(GridKernalContext ctx) {
+        assert ctx != null;
+
+        this.ctx = ctx;
+    }
+
+    /** {@inheritDoc} */
+    @Override public BinaryObjectImpl deserialize(JsonParser parser, DeserializationContext dCtx) throws IOException {
+        String type = (String)dCtx.findInjectableValue(BINARY_TYPE_PROPERTY, null, null);
+        String cacheName = (String)dCtx.findInjectableValue(CACHE_NAME_PROPERTY, null, null);
+
+        assert type != null;
+
+        if (ctx.marshallerContext().isSystemType(type))
+            throw new IllegalArgumentException("Cannot make binary object [type=" + type + "]");
+
+        ObjectCodec mapper = parser.getCodec();
+        JsonNode jsonTree = mapper.readTree(parser);
+
+        return (BinaryObjectImpl)deserialize0(cacheName, type, jsonTree, mapper);
+    }
+
+    /**
+     * @param cacheName Cache name.
+     * @param type Type name.
+     * @param node JSON node.
+     * @param mapper JSON object mapper.
+     * @return Deserialized object.
+     * @throws IOException In case of error.
+     */
+    private Object deserialize0(String cacheName, String type, JsonNode node, ObjectCodec mapper) throws IOException {
+        if (ctx.marshallerContext().isSystemType(type)) {
+            Class<?> cls = IgniteUtils.classForName(type, null);
+
+            if (cls != null)
+                return mapper.treeToValue(node, cls);
+        }
+
+        BinaryType binType = ctx.cacheObjects().binary().type(type);
+
+        Deserializer deserializer = binType instanceof BinaryTypeImpl ?
+            new BinaryTypeDeserializer(cacheName, (BinaryTypeImpl)binType, mapper) :
+            new Deserializer(cacheName, type, mapper);
+
+        return deserializer.deserialize(node);
+    }
+
+    /**
+     * JSON deserializer creates a new binary type using JSON data types.
+     */
+    private class Deserializer {
+        /** New binary type name. */
+        private final String type;
+
+        /** Cache query meta. */
+        protected final Map<String, Class<?>> qryFields;
+
+        /** Cache name. */
+        protected final String cacheName;
+
+        /** JSON object mapper. */
+        protected final ObjectCodec mapper;
+
+        /**
+         * @param cacheName Cache name.
+         * @param type Type name.
+         * @param mapper JSON object mapper.
+         */
+        public Deserializer(@Nullable String cacheName, String type, ObjectCodec mapper) {
+            this.type = type;
+            this.mapper = mapper;
+            this.cacheName = cacheName;
+
+            qryFields = qryFields();
+        }
+
+        /**
+         * @return Mapping from field name to its type.
+         */
+        private Map<String, Class<?>> qryFields() {
+            if (ctx.query().moduleEnabled()) {
+                QueryTypeDescriptorImpl desc = ctx.query().typeDescriptor(cacheName, type);
+
+                if (desc != null)
+                    return desc.fields();
+            }
+
+            return Collections.emptyMap();
+        }
+
+        /**
+         * Deserialize JSON tree.
+         *
+         * @param tree JSON tree node.
+         * @return Binary object.
+         * @throws IOException In case of error.
+         */
+        public BinaryObject deserialize(JsonNode tree) throws IOException {
+            return binaryValue(type, tree);
+        }
+
+        /**
+         * @param type Ignite binary type name.
+         * @param tree JSON tree node.
+         * @return Binary object.
+         * @throws IOException In case of error.
+         */
+        private BinaryObject binaryValue(String type, JsonNode tree) throws IOException {
+            BinaryObjectBuilder builder = ctx.cacheObjects().builder(type);
+
+            Iterator<Map.Entry<String, JsonNode>> itr = tree.fields();
+
+            while (itr.hasNext()) {
+                Map.Entry<String, JsonNode> entry = itr.next();
+
+                String field = entry.getKey();
+                Object val = readValue(field, entry.getValue());
+
+                builder.setField(field, val);
+            }
+
+            return builder.build();
+        }
+
+        /**
+         * @param field Field name.
+         * @param jsonNode JSON node.
+         * @return value.
+         * @throws IOException In case of error.
+         */
+        protected Object readValue(String field, JsonNode jsonNode) throws IOException {
+            JsonNodeType nodeType = jsonNode.getNodeType();
+
+            if (nodeType == JsonNodeType.BINARY)
+                return jsonNode.binaryValue();
+
+            if (nodeType == JsonNodeType.BOOLEAN)
+                return jsonNode.booleanValue();
+
+            Class<?> cls = qryFields.get(field.toUpperCase());
+
+            if (cls != null)
+                return mapper.treeToValue(jsonNode, cls);
+
+            switch (nodeType) {
+                case ARRAY:
+                    List<Object> list = new ArrayList<>(jsonNode.size());
+                    Iterator<JsonNode> itr = jsonNode.elements();
+
+                    while (itr.hasNext())
+                        list.add(readValue(field, itr.next()));
+
+                    return list;
+
+                case NUMBER:
+                    return jsonNode.numberValue();
+
+                case OBJECT:
+                    return mapper.treeToValue(jsonNode, cls);
+
+                case STRING:
+                    return jsonNode.asText();
+
+                default:
+                    return null;
+            }
+        }
+    }
+
+    /**
+     * JSON deserializer using the existing Ignite binary type.
+     */
+    private class BinaryTypeDeserializer extends Deserializer {
+        /** Binary type. */
+        private final BinaryTypeImpl binType;
+
+        /** Binary class descriptor. */
+        private final BinaryClassDescriptor binClsDesc;
+
+        /**
+         * @param cacheName Cache name.
+         * @param binaryType Binary type.
+         * @param mapper JSON object mapper.
+         */
+        public BinaryTypeDeserializer(@Nullable String cacheName, BinaryTypeImpl binaryType, ObjectCodec mapper) {
+            super(cacheName, binaryType.typeName(), mapper);
+
+            binType = binaryType;
+            binClsDesc = binaryClassDescriptor();
+        }
+
+        /** {@inheritDoc} */
+        @Override public BinaryObject deserialize(JsonNode tree) throws IOException {
+            BinaryObjectBuilder builder = ctx.cacheObjects().builder(binType.typeName());
+            Map<String, BinaryFieldMetadata> metas = binType.metadata().fieldsMap();
+
+            Iterator<Map.Entry<String, JsonNode>> itr = tree.fields();
+
+            while (itr.hasNext()) {
+                Map.Entry<String, JsonNode> entry = itr.next();
+
+                String field = entry.getKey();
+                JsonNode node = tree.get(field);
+                BinaryFieldMetadata meta = metas.get(field);
+
+                Object val = meta != null ?
+                    readValue(meta.typeId(), field, node, binType) : readValue(field, node);
+
+                builder.setField(field, val);
+            }
+
+            return builder.build();
+        }
+
+        /**
+         * Extract and cast JSON node value into required object format.
+         *
+         * @param type Field type.
+         * @param field Field name.
+         * @param node JSON node.
+         * @param parentType Parent type.
+         * @return Extracted value.
+         * @throws IOException if failed.
+         */
+        private Object readValue(int type, String field, JsonNode node, BinaryTypeImpl parentType) throws IOException {
+            Class<?> baseCls;
+
+            switch (type) {
+                case GridBinaryMarshaller.MAP:
+                    baseCls = Map.class;
+
+                    break;
+                case GridBinaryMarshaller.OBJ_ARR:
+                case GridBinaryMarshaller.COL:
+                case GridBinaryMarshaller.OBJ:
+                case GridBinaryMarshaller.ENUM:
+                    baseCls = fieldClass(field);
+
+                    if (baseCls == null)
+                        return readValue(field, node);
+
+                    break;
+                default:
+                    baseCls = BinaryUtils.FLAG_TO_CLASS.get((byte)type);
+            }
+
+            if (baseCls != null)
+                return mapper.treeToValue(node, baseCls);
+
+            return deserialize0(cacheName, parentType.fieldTypeName(field), node, mapper);
+        }
+
+        /**
+         * @return Class descriptor for current binary type or {@code null} if the class was not found.
+         */
+        private @Nullable BinaryClassDescriptor binaryClassDescriptor() {
+            try {
+                return binType.context().descriptorForTypeId(false, binType.typeId(),null,false);
 
 Review comment:
   Add whitespace please

----------------------------------------------------------------
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

[GitHub] [ignite] alex-plekhanov commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST

Posted by GitBox <gi...@apache.org>.
alex-plekhanov commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST
URL: https://github.com/apache/ignite/pull/7648#discussion_r410118857
 
 

 ##########
 File path: modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java
 ##########
 @@ -2878,6 +3134,341 @@ public void ref(CircularRef ref) {
         }
     }
 
+    /** */
+    @JsonInclude(JsonInclude.Include.NON_NULL)
+    @SuppressWarnings("AssignmentOrReturnOfFieldWithMutableType")
+    public static class OuterClass {
+        /** */
+        private long id;
+
+        /** */
+        private String name;
+
+        /** */
+        private double doubleVal;
+
+        /** */
+        private Boolean optional;
+
+        /** */
+        private ArrayList<Integer> list;
+
+        /** */
+        private Timestamp timestamp;
+
+        /** */
+        private long[] longs;
+
+        /** */
+        OuterClass() {
+            // No-op.
+        }
+
+        /** */
+        OuterClass(long id, String name, double doubleVal, List<Integer> list, @Nullable Boolean optional) {
+            this.id = id;
+            this.name = name;
+            this.doubleVal = doubleVal;
+            this.list = new ArrayList<>(list);
+            this.optional = optional;
+        }
+
+        /** */
+        public long getId() {
+            return id;
+        }
+
+        /** */
+        public String getName() {
+            return name;
+        }
+
+        /** */
+        public Boolean getOptional() {
+            return optional;
+        }
+
+        /** */
+        public double getDoubleVal() {
+            return doubleVal;
+        }
+
+        /** */
+        public ArrayList<Integer> getList() {
+            return list;
+        }
+
+        /** */
+        public Timestamp getTimestamp() {
+            return timestamp;
+        }
+
+        /** */
+        public long[] getLongs() {
+            return longs;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean equals(Object o) {
+            if (this == o)
+                return true;
+            if (o == null || getClass() != o.getClass())
+                return false;
+            OuterClass aClass = (OuterClass)o;
+            return id == aClass.id &&
+                Double.compare(aClass.doubleVal, doubleVal) == 0 &&
+                Objects.equals(name, aClass.name) &&
+                Objects.equals(optional, aClass.optional) &&
+                Objects.equals(list, aClass.list) &&
+                Objects.equals(timestamp, aClass.timestamp) &&
+                Arrays.equals(longs, aClass.longs);
+        }
+
+        /** {@inheritDoc} */
+        @Override public int hashCode() {
+            return Objects.hash(id, name, optional, doubleVal, list, timestamp, longs);
+        }
+
+        /** {@inheritDoc} */
+        @Override public String toString() {
+            return "OuterClass{" +
+                "id=" + id +
+                ", name='" + name + '\'' +
+                ", doubleVal=" + doubleVal +
+                ", optional=" + optional +
+                ", list=" + list +
+                ", timestamp=" + timestamp +
+                ", bytes=" + Arrays.toString(longs) +
+                '}';
+        }
+    }
+
+    /** */
+    public enum COLOR {
 
 Review comment:
   `COLOR` -> `Color`

----------------------------------------------------------------
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

[GitHub] [ignite] xtern commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST

Posted by GitBox <gi...@apache.org>.
xtern commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST
URL: https://github.com/apache/ignite/pull/7648#discussion_r409891872
 
 

 ##########
 File path: modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
 ##########
 @@ -1106,6 +1017,139 @@ private boolean credentials(Map<String, Object> params, String userParam, String
         return null;
     }
 
+    /** */
+    private class Converter {
+        /** Cache name. */
+        private final String cacheName;
+
+        /**
+         * @param cacheName Cache name.
+         */
+        private Converter(String cacheName) {
+            this.cacheName = cacheName;
+        }
+
+        /** */
+        private Converter() {
+            this(null);
+        }
+
+        /**
+         * Gets and converts values referenced by sequential keys, e.g. {@code key1...keyN}.
+         *
+         * @param type Optional value type.
+         * @param keyPrefix Key prefix, e.g. {@code key} for {@code key1...keyN}.
+         * @param params Parameters map.
+         * @return Values.
+         */
+        private List<Object> values(String type, String keyPrefix,
+            Map<String, String> params) throws IgniteCheckedException {
+            assert keyPrefix != null;
+
+            List<Object> vals = new LinkedList<>();
+
+            for (int i = 1; ; i++) {
+                String key = keyPrefix + i;
+
+                if (params.containsKey(key))
+                    vals.add(convert(type, params.get(key)));
+                else
+                    break;
+            }
+
+            return vals;
+        }
+
+        /**
+         * @param type Optional value type.
+         * @param s String to convert.
+         * @return Converted value.
+         * @throws IgniteCheckedException If failed to convert.
+         */
+        private Object convert(String type, String s) throws IgniteCheckedException {
+            if (F.isEmpty(type) || s == null)
 
 Review comment:
   added Nullable
   
   _Can s be checked with F.empty too?_
   not sure, 

----------------------------------------------------------------
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

[GitHub] [ignite] xtern commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST

Posted by GitBox <gi...@apache.org>.
xtern commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST
URL: https://github.com/apache/ignite/pull/7648#discussion_r409870188
 
 

 ##########
 File path: modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyObjectMapper.java
 ##########
 @@ -264,4 +292,36 @@ private void writeException(Throwable e, JsonGenerator gen) throws IOException {
             }
         }
     };
+
+    /** Custom serializer for {@link java.sql.Timestamp}. */
+    private static final JsonSerializer<Timestamp> IGNITE_TIMESTAMP_SERIALIZER = new JsonSerializer<Timestamp>() {
+        /** {@inheritDoc} */
 
 Review comment:
   Thanks, 
   I missed javadocs in similar places, actually.

----------------------------------------------------------------
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

[GitHub] [ignite] alex-plekhanov commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST

Posted by GitBox <gi...@apache.org>.
alex-plekhanov commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST
URL: https://github.com/apache/ignite/pull/7648#discussion_r410118649
 
 

 ##########
 File path: modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java
 ##########
 @@ -2878,6 +3163,276 @@ public void ref(CircularRef ref) {
         }
     }
 
+    /** */
+    @JsonInclude(JsonInclude.Include.NON_NULL)
+    public static class OuterClass {
+        /** */
+        @JsonProperty
+        private long id;
+
+        /** */
+        @JsonProperty
+        private String name;
+
+        /** */
+        @JsonProperty
+        private double doubleVal;
+
+        /** */
+        @JsonProperty
+        private Boolean optional;
+
+        /** */
+        @JsonProperty
+        private ArrayList<Integer> list;
+
+        /** */
+        @JsonProperty
+        private Timestamp timestamp;
+
+        /** */
+        @JsonProperty
+        private long[] longs;
+
+        /** */
+        OuterClass() {
+            // No-op.
+        }
+
+        /** */
+        OuterClass(long id, String name, double doubleVal, List<Integer> list) {
+            this(id, name, doubleVal, list, null, null, null);
+        }
+
+        /** */
+        @SuppressWarnings("AssignmentOrReturnOfFieldWithMutableType")
+        OuterClass(long id, String name, double doubleVal, List<Integer> list, Timestamp ts, long[] longs, Boolean b) {
+            this.id = id;
+            this.name = name;
+            this.doubleVal = doubleVal;
+            this.list = new ArrayList<>(list);
+            this.timestamp = ts;
+            this.longs = longs;
+            this.optional = b;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean equals(Object o) {
+            if (this == o)
+                return true;
+
+            if (o == null || getClass() != o.getClass())
+                return false;
+
+            OuterClass aCls = (OuterClass)o;
+
+            return id == aCls.id &&
+                Double.compare(aCls.doubleVal, doubleVal) == 0 &&
+                Objects.equals(name, aCls.name) &&
+                Objects.equals(optional, aCls.optional) &&
+                Objects.equals(list, aCls.list) &&
+                Objects.equals(timestamp, aCls.timestamp) &&
+                Arrays.equals(longs, aCls.longs);
+        }
+
+        /** {@inheritDoc} */
+        @Override public int hashCode() {
+            return Objects.hash(id, name, optional, doubleVal, list, timestamp, longs);
+        }
+
+        /** {@inheritDoc} */
+        @Override public String toString() {
+            return "OuterClass [" +
+                "id=" + id +
+                ", name='" + name + '\'' +
+                ", doubleVal=" + doubleVal +
+                ", optional=" + optional +
+                ", list=" + list +
+                ", timestamp=" + timestamp +
+                ", bytes=" + Arrays.toString(longs) +
+                ']';
+        }
+    }
+
+    /** */
+    public enum COLOR {
+        /** */
+        RED,
+
+        /** */
+        GREEN,
+
+        /** */
+        BLUE
+    }
+
+    /** Complex entity. */
+    @SuppressWarnings({"InnerClassMayBeStatic", "AssignmentOrReturnOfFieldWithMutableType"})
+    static class Complex implements Serializable {
 
 Review comment:
   Let's test also UUID and IgniteUud types

----------------------------------------------------------------
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

[GitHub] [ignite] xtern commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST

Posted by GitBox <gi...@apache.org>.
xtern commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST
URL: https://github.com/apache/ignite/pull/7648#discussion_r409840217
 
 

 ##########
 File path: modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/IgniteBinaryObjectJsonDeserializer.java
 ##########
 @@ -0,0 +1,343 @@
+/*
+ * 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.ignite.internal.processors.rest.protocols.http.jetty;
+
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.ObjectCodec;
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.JsonDeserializer;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.JsonNodeType;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.binary.BinaryObjectBuilder;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryType;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.binary.BinaryClassDescriptor;
+import org.apache.ignite.internal.binary.BinaryFieldMetadata;
+import org.apache.ignite.internal.binary.BinaryObjectImpl;
+import org.apache.ignite.internal.binary.BinaryTypeImpl;
+import org.apache.ignite.internal.binary.BinaryUtils;
+import org.apache.ignite.internal.binary.GridBinaryMarshaller;
+import org.apache.ignite.internal.processors.cache.GridCacheUtils;
+import org.apache.ignite.internal.processors.query.QueryTypeDescriptorImpl;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * JSON deserializer into the Ignite binary object.
+ */
+public class IgniteBinaryObjectJsonDeserializer extends JsonDeserializer {
+    /** Property name to set binary type name. */
+    public static final String BINARY_TYPE_PROPERTY = "binaryTypeName";
+
+    /** Property name to set cache name. */
+    public static final String CACHE_NAME_PROPERTY = "cacheName";
+
+    /** Kernal context. */
+    private final GridKernalContext ctx;
+
+    /**
+     * @param ctx Kernal context.
+     */
+    public IgniteBinaryObjectJsonDeserializer(GridKernalContext ctx) {
+        assert ctx != null;
+
+        this.ctx = ctx;
+    }
+
+    /** {@inheritDoc} */
+    @Override public BinaryObjectImpl deserialize(JsonParser parser, DeserializationContext dCtx) throws IOException {
+        String type = (String)dCtx.findInjectableValue(BINARY_TYPE_PROPERTY, null, null);
+        String cacheName = (String)dCtx.findInjectableValue(CACHE_NAME_PROPERTY, null, null);
+
+        assert type != null;
+        assert !ctx.marshallerContext().isSystemType(type);
 
 Review comment:
   Done
   (Throwing IllegalArgumentException in this case)

----------------------------------------------------------------
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

[GitHub] [ignite] xtern commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST

Posted by GitBox <gi...@apache.org>.
xtern commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST
URL: https://github.com/apache/ignite/pull/7648#discussion_r409870188
 
 

 ##########
 File path: modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyObjectMapper.java
 ##########
 @@ -264,4 +292,36 @@ private void writeException(Throwable e, JsonGenerator gen) throws IOException {
             }
         }
     };
+
+    /** Custom serializer for {@link java.sql.Timestamp}. */
+    private static final JsonSerializer<Timestamp> IGNITE_TIMESTAMP_SERIALIZER = new JsonSerializer<Timestamp>() {
+        /** {@inheritDoc} */
 
 Review comment:
   Thanks, 
   I missed javadocs in similar places, actually.

----------------------------------------------------------------
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

[GitHub] [ignite] NSAmelchev commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST

Posted by GitBox <gi...@apache.org>.
NSAmelchev commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST
URL: https://github.com/apache/ignite/pull/7648#discussion_r409864128
 
 

 ##########
 File path: modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
 ##########
 @@ -1106,6 +1016,139 @@ private boolean credentials(Map<String, Object> params, String userParam, String
         return null;
     }
 
+    /** */
+    private class Converter {
+        /** Cache name. */
+        private final String cacheName;
+
+        /**
+         * @param cacheName Cache name.
+         */
+        private Converter(String cacheName) {
+            this.cacheName = cacheName;
+        }
+
+        /** */
+        private Converter() {
+            this(null);
+        }
+
+        /**
+         * Gets and converts values referenced by sequential keys, e.g. {@code key1...keyN}.
+         *
+         * @param type Optional value type.
+         * @param keyPrefix Key prefix, e.g. {@code key} for {@code key1...keyN}.
+         * @param params Parameters map.
+         * @return Values.
 
 Review comment:
   Missed Throws javadoc

----------------------------------------------------------------
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

[GitHub] [ignite] xtern commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST

Posted by GitBox <gi...@apache.org>.
xtern commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST
URL: https://github.com/apache/ignite/pull/7648#discussion_r410150178
 
 

 ##########
 File path: modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java
 ##########
 @@ -2878,6 +3163,276 @@ public void ref(CircularRef ref) {
         }
     }
 
+    /** */
+    @JsonInclude(JsonInclude.Include.NON_NULL)
+    public static class OuterClass {
+        /** */
+        @JsonProperty
+        private long id;
+
+        /** */
+        @JsonProperty
+        private String name;
+
+        /** */
+        @JsonProperty
+        private double doubleVal;
+
+        /** */
+        @JsonProperty
+        private Boolean optional;
+
+        /** */
+        @JsonProperty
+        private ArrayList<Integer> list;
+
+        /** */
+        @JsonProperty
+        private Timestamp timestamp;
+
+        /** */
+        @JsonProperty
+        private long[] longs;
+
+        /** */
+        OuterClass() {
+            // No-op.
+        }
+
+        /** */
+        OuterClass(long id, String name, double doubleVal, List<Integer> list) {
+            this(id, name, doubleVal, list, null, null, null);
+        }
+
+        /** */
+        @SuppressWarnings("AssignmentOrReturnOfFieldWithMutableType")
+        OuterClass(long id, String name, double doubleVal, List<Integer> list, Timestamp ts, long[] longs, Boolean b) {
+            this.id = id;
+            this.name = name;
+            this.doubleVal = doubleVal;
+            this.list = new ArrayList<>(list);
+            this.timestamp = ts;
+            this.longs = longs;
+            this.optional = b;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean equals(Object o) {
+            if (this == o)
+                return true;
+
+            if (o == null || getClass() != o.getClass())
+                return false;
+
+            OuterClass aCls = (OuterClass)o;
+
+            return id == aCls.id &&
+                Double.compare(aCls.doubleVal, doubleVal) == 0 &&
+                Objects.equals(name, aCls.name) &&
+                Objects.equals(optional, aCls.optional) &&
+                Objects.equals(list, aCls.list) &&
+                Objects.equals(timestamp, aCls.timestamp) &&
+                Arrays.equals(longs, aCls.longs);
+        }
+
+        /** {@inheritDoc} */
+        @Override public int hashCode() {
+            return Objects.hash(id, name, optional, doubleVal, list, timestamp, longs);
+        }
+
+        /** {@inheritDoc} */
+        @Override public String toString() {
+            return "OuterClass [" +
+                "id=" + id +
+                ", name='" + name + '\'' +
+                ", doubleVal=" + doubleVal +
+                ", optional=" + optional +
+                ", list=" + list +
+                ", timestamp=" + timestamp +
+                ", bytes=" + Arrays.toString(longs) +
+                ']';
+        }
+    }
+
+    /** */
+    public enum COLOR {
+        /** */
+        RED,
+
+        /** */
+        GREEN,
+
+        /** */
+        BLUE
+    }
+
+    /** Complex entity. */
+    @SuppressWarnings({"InnerClassMayBeStatic", "AssignmentOrReturnOfFieldWithMutableType"})
+    static class Complex implements Serializable {
 
 Review comment:
   Done.

----------------------------------------------------------------
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

[GitHub] [ignite] NSAmelchev commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST

Posted by GitBox <gi...@apache.org>.
NSAmelchev commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST
URL: https://github.com/apache/ignite/pull/7648#discussion_r409876977
 
 

 ##########
 File path: modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
 ##########
 @@ -1106,6 +1017,139 @@ private boolean credentials(Map<String, Object> params, String userParam, String
         return null;
     }
 
+    /** */
+    private class Converter {
+        /** Cache name. */
+        private final String cacheName;
+
+        /**
+         * @param cacheName Cache name.
+         */
+        private Converter(String cacheName) {
+            this.cacheName = cacheName;
+        }
+
+        /** */
+        private Converter() {
+            this(null);
+        }
+
+        /**
+         * Gets and converts values referenced by sequential keys, e.g. {@code key1...keyN}.
+         *
+         * @param type Optional value type.
+         * @param keyPrefix Key prefix, e.g. {@code key} for {@code key1...keyN}.
+         * @param params Parameters map.
+         * @return Values.
+         */
+        private List<Object> values(String type, String keyPrefix,
+            Map<String, String> params) throws IgniteCheckedException {
+            assert keyPrefix != null;
+
+            List<Object> vals = new LinkedList<>();
+
+            for (int i = 1; ; i++) {
+                String key = keyPrefix + i;
+
+                if (params.containsKey(key))
+                    vals.add(convert(type, params.get(key)));
+                else
+                    break;
+            }
+
+            return vals;
+        }
+
+        /**
+         * @param type Optional value type.
+         * @param s String to convert.
+         * @return Converted value.
+         * @throws IgniteCheckedException If failed to convert.
+         */
+        private Object convert(String type, String s) throws IgniteCheckedException {
+            if (F.isEmpty(type) || s == null)
 
 Review comment:
   Can `s` be checked with `F.empty` too? Mark parametr as nullable, please.

----------------------------------------------------------------
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

[GitHub] [ignite] NSAmelchev commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST

Posted by GitBox <gi...@apache.org>.
NSAmelchev commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST
URL: https://github.com/apache/ignite/pull/7648#discussion_r409862998
 
 

 ##########
 File path: modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyObjectMapper.java
 ##########
 @@ -264,4 +292,36 @@ private void writeException(Throwable e, JsonGenerator gen) throws IOException {
             }
         }
     };
+
+    /** Custom serializer for {@link java.sql.Timestamp}. */
+    private static final JsonSerializer<Timestamp> IGNITE_TIMESTAMP_SERIALIZER = new JsonSerializer<Timestamp>() {
+        /** {@inheritDoc} */
 
 Review comment:
   redundant javadoc

----------------------------------------------------------------
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

[GitHub] [ignite] xtern commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST

Posted by GitBox <gi...@apache.org>.
xtern commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST
URL: https://github.com/apache/ignite/pull/7648#discussion_r409891583
 
 

 ##########
 File path: modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
 ##########
 @@ -1106,6 +1016,139 @@ private boolean credentials(Map<String, Object> params, String userParam, String
         return null;
     }
 
+    /** */
 
 Review comment:
   done

----------------------------------------------------------------
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

[GitHub] [ignite] xtern commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST

Posted by GitBox <gi...@apache.org>.
xtern commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST
URL: https://github.com/apache/ignite/pull/7648#discussion_r409839448
 
 

 ##########
 File path: modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java
 ##########
 @@ -2878,6 +3134,341 @@ public void ref(CircularRef ref) {
         }
     }
 
+    /** */
+    @JsonInclude(JsonInclude.Include.NON_NULL)
+    @SuppressWarnings("AssignmentOrReturnOfFieldWithMutableType")
+    public static class OuterClass {
+        /** */
+        private long id;
+
+        /** */
+        private String name;
+
+        /** */
+        private double doubleVal;
+
+        /** */
+        private Boolean optional;
+
+        /** */
+        private ArrayList<Integer> list;
+
+        /** */
+        private Timestamp timestamp;
+
+        /** */
+        private long[] longs;
+
+        /** */
+        OuterClass() {
+            // No-op.
+        }
+
+        /** */
+        OuterClass(long id, String name, double doubleVal, List<Integer> list, @Nullable Boolean optional) {
+            this.id = id;
+            this.name = name;
+            this.doubleVal = doubleVal;
+            this.list = new ArrayList<>(list);
+            this.optional = optional;
+        }
+
+        /** */
+        public long getId() {
+            return id;
+        }
+
+        /** */
+        public String getName() {
+            return name;
+        }
+
+        /** */
+        public Boolean getOptional() {
+            return optional;
+        }
+
+        /** */
+        public double getDoubleVal() {
+            return doubleVal;
+        }
+
+        /** */
+        public ArrayList<Integer> getList() {
+            return list;
+        }
+
+        /** */
+        public Timestamp getTimestamp() {
+            return timestamp;
+        }
+
+        /** */
+        public long[] getLongs() {
+            return longs;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean equals(Object o) {
+            if (this == o)
+                return true;
+            if (o == null || getClass() != o.getClass())
+                return false;
+            OuterClass aClass = (OuterClass)o;
+            return id == aClass.id &&
+                Double.compare(aClass.doubleVal, doubleVal) == 0 &&
+                Objects.equals(name, aClass.name) &&
+                Objects.equals(optional, aClass.optional) &&
+                Objects.equals(list, aClass.list) &&
+                Objects.equals(timestamp, aClass.timestamp) &&
+                Arrays.equals(longs, aClass.longs);
+        }
+
+        /** {@inheritDoc} */
+        @Override public int hashCode() {
+            return Objects.hash(id, name, optional, doubleVal, list, timestamp, longs);
+        }
+
+        /** {@inheritDoc} */
+        @Override public String toString() {
+            return "OuterClass{" +
+                "id=" + id +
+                ", name='" + name + '\'' +
+                ", doubleVal=" + doubleVal +
+                ", optional=" + optional +
+                ", list=" + list +
+                ", timestamp=" + timestamp +
+                ", bytes=" + Arrays.toString(longs) +
+                '}';
+        }
+    }
+
+    /** */
+    public enum COLOR {
+        RED,
+        GREEN,
+        BLUE
+    }
+
+    /** Complex entity. */
+    @SuppressWarnings({"InnerClassMayBeStatic", "AssignmentOrReturnOfFieldWithMutableType"})
+    static class Complex implements Serializable {
+        /** */
+        @QuerySqlField(index = true)
+        private Integer id;
+
+        /** */
+        @QuerySqlField
+        private String string;
 
 Review comment:
   Dnne

----------------------------------------------------------------
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

[GitHub] [ignite] alex-plekhanov commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST

Posted by GitBox <gi...@apache.org>.
alex-plekhanov commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST
URL: https://github.com/apache/ignite/pull/7648#discussion_r409532161
 
 

 ##########
 File path: modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
 ##########
 @@ -876,9 +805,11 @@ else if (cmd == CLUSTER_ACTIVE || cmd == CLUSTER_ACTIVATE)
             case EXECUTE_SQL_FIELDS_QUERY: {
                 RestQueryRequest restReq0 = new RestQueryRequest();
 
+                String cacheName = (String)params.get(CACHE_NAME_PARAM);
+
                 restReq0.sqlQuery((String)params.get("qry"));
 
-                restReq0.arguments(values(null, "arg", params).toArray());
+                restReq0.arguments(new Converter(cacheName).values( null, "arg", params).toArray());
 
 Review comment:
   Redundant space

----------------------------------------------------------------
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

[GitHub] [ignite] xtern commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST

Posted by GitBox <gi...@apache.org>.
xtern commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST
URL: https://github.com/apache/ignite/pull/7648#discussion_r409892029
 
 

 ##########
 File path: modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java
 ##########
 @@ -2778,6 +2991,87 @@ protected void initCache() {
         assertEquals(2, personCache.query(qry).getAll().size());
     }
 
+    /**
+     * @param cacheName Cache name.
+     * @param key Cache key.
+     * @param obj Cache value.
+     * @throws Exception If failed.
+     */
+    private void putObject(String cacheName, String key, Object obj) throws Exception {
+        putObject(cacheName, key, obj, obj.getClass().getName());
+    }
+
+    /**
+     * @param cacheName Cache name.
+     * @param key Cache key.
+     * @param obj Cache value.
+     * @param type Cache value type.
+     * @throws Exception If failed.
+     */
+    private void putObject(String cacheName, String key, Object obj, String type) throws Exception {
+        String json = JSON_MAPPER.writeValueAsString(obj);
+
+        info("Put: " + json);
+
+        String ret = content(cacheName, GridRestCommand.CACHE_PUT,
+            "keyType", "int",
+            "key", key,
+            "valueType", type,
+            "val", json
+        );
+
+        info("Put command result: " + ret);
+
+        assertResponseSucceeded(ret, false);
+    }
+
+    /**
+     * @param cacheName Cache name.
+     * @param key Cache key.
+     * @param cls Cache value class.
+     * @param <T> Cache value type.
+     * @return Deserialized object of type {@code T}.
+     * @throws Exception If failed.
+     */
+    private <T> T getObject(String cacheName, String key, Class<T> cls) throws Exception {
+        String ret = content(cacheName, GridRestCommand.CACHE_GET, "keyType", "int", "key", key);
+
+        info("Get command result: " + ret);
+
+        JsonNode res = assertResponseSucceeded(ret, false);
+
+        return JSON_MAPPER.treeToValue(res, cls);
+    }
+
+    /**
+     * @param cacheName Cache name.
+     * @param params Query parameters.
+     * @return Json query result.
+     * @throws Exception If failed.
+     */
+    private JsonNode queryObject(String cacheName, String ... params) throws Exception {
 
 Review comment:
   Done

----------------------------------------------------------------
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

[GitHub] [ignite] xtern commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST

Posted by GitBox <gi...@apache.org>.
xtern commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST
URL: https://github.com/apache/ignite/pull/7648#discussion_r409839084
 
 

 ##########
 File path: modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
 ##########
 @@ -876,9 +805,11 @@ else if (cmd == CLUSTER_ACTIVE || cmd == CLUSTER_ACTIVATE)
             case EXECUTE_SQL_FIELDS_QUERY: {
                 RestQueryRequest restReq0 = new RestQueryRequest();
 
+                String cacheName = (String)params.get(CACHE_NAME_PARAM);
+
                 restReq0.sqlQuery((String)params.get("qry"));
 
-                restReq0.arguments(values(null, "arg", params).toArray());
+                restReq0.arguments(new Converter(cacheName).values( null, "arg", params).toArray());
 
 Review comment:
   Fixed

----------------------------------------------------------------
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

[GitHub] [ignite] alex-plekhanov commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST

Posted by GitBox <gi...@apache.org>.
alex-plekhanov commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST
URL: https://github.com/apache/ignite/pull/7648#discussion_r409552743
 
 

 ##########
 File path: modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/IgniteBinaryObjectJsonDeserializer.java
 ##########
 @@ -0,0 +1,343 @@
+/*
+ * 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.ignite.internal.processors.rest.protocols.http.jetty;
+
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.ObjectCodec;
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.JsonDeserializer;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.JsonNodeType;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.binary.BinaryObjectBuilder;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryType;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.binary.BinaryClassDescriptor;
+import org.apache.ignite.internal.binary.BinaryFieldMetadata;
+import org.apache.ignite.internal.binary.BinaryObjectImpl;
+import org.apache.ignite.internal.binary.BinaryTypeImpl;
+import org.apache.ignite.internal.binary.BinaryUtils;
+import org.apache.ignite.internal.binary.GridBinaryMarshaller;
+import org.apache.ignite.internal.processors.cache.GridCacheUtils;
+import org.apache.ignite.internal.processors.query.QueryTypeDescriptorImpl;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * JSON deserializer into the Ignite binary object.
+ */
+public class IgniteBinaryObjectJsonDeserializer extends JsonDeserializer {
 
 Review comment:
   `JsonDeserializer<BinaryObjectImpl>`

----------------------------------------------------------------
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

[GitHub] [ignite] NSAmelchev commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST

Posted by GitBox <gi...@apache.org>.
NSAmelchev commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST
URL: https://github.com/apache/ignite/pull/7648#discussion_r409862998
 
 

 ##########
 File path: modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyObjectMapper.java
 ##########
 @@ -264,4 +292,36 @@ private void writeException(Throwable e, JsonGenerator gen) throws IOException {
             }
         }
     };
+
+    /** Custom serializer for {@link java.sql.Timestamp}. */
+    private static final JsonSerializer<Timestamp> IGNITE_TIMESTAMP_SERIALIZER = new JsonSerializer<Timestamp>() {
+        /** {@inheritDoc} */
 
 Review comment:
   redundant javadoc

----------------------------------------------------------------
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

[GitHub] [ignite] alex-plekhanov commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST

Posted by GitBox <gi...@apache.org>.
alex-plekhanov commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST
URL: https://github.com/apache/ignite/pull/7648#discussion_r409541147
 
 

 ##########
 File path: modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/IgniteBinaryObjectJsonDeserializer.java
 ##########
 @@ -0,0 +1,343 @@
+/*
+ * 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.ignite.internal.processors.rest.protocols.http.jetty;
+
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.ObjectCodec;
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.JsonDeserializer;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.JsonNodeType;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.binary.BinaryObjectBuilder;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryType;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.binary.BinaryClassDescriptor;
+import org.apache.ignite.internal.binary.BinaryFieldMetadata;
+import org.apache.ignite.internal.binary.BinaryObjectImpl;
+import org.apache.ignite.internal.binary.BinaryTypeImpl;
+import org.apache.ignite.internal.binary.BinaryUtils;
+import org.apache.ignite.internal.binary.GridBinaryMarshaller;
+import org.apache.ignite.internal.processors.cache.GridCacheUtils;
+import org.apache.ignite.internal.processors.query.QueryTypeDescriptorImpl;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * JSON deserializer into the Ignite binary object.
+ */
+public class IgniteBinaryObjectJsonDeserializer extends JsonDeserializer {
+    /** Property name to set binary type name. */
+    public static final String BINARY_TYPE_PROPERTY = "binaryTypeName";
+
+    /** Property name to set cache name. */
+    public static final String CACHE_NAME_PROPERTY = "cacheName";
+
+    /** Kernal context. */
+    private final GridKernalContext ctx;
+
+    /**
+     * @param ctx Kernal context.
+     */
+    public IgniteBinaryObjectJsonDeserializer(GridKernalContext ctx) {
+        assert ctx != null;
+
+        this.ctx = ctx;
+    }
+
+    /** {@inheritDoc} */
+    @Override public BinaryObjectImpl deserialize(JsonParser parser, DeserializationContext dCtx) throws IOException {
+        String type = (String)dCtx.findInjectableValue(BINARY_TYPE_PROPERTY, null, null);
+        String cacheName = (String)dCtx.findInjectableValue(CACHE_NAME_PROPERTY, null, null);
+
+        assert type != null;
+        assert !ctx.marshallerContext().isSystemType(type);
 
 Review comment:
   Here we should throw an exception with the correct message, but not assert this value, since user can pass system type and you didn't check it before.

----------------------------------------------------------------
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

[GitHub] [ignite] xtern commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST

Posted by GitBox <gi...@apache.org>.
xtern commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST
URL: https://github.com/apache/ignite/pull/7648#discussion_r409891437
 
 

 ##########
 File path: modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
 ##########
 @@ -1106,6 +1016,139 @@ private boolean credentials(Map<String, Object> params, String userParam, String
         return null;
     }
 
+    /** */
+    private class Converter {
+        /** Cache name. */
+        private final String cacheName;
+
+        /**
+         * @param cacheName Cache name.
+         */
+        private Converter(String cacheName) {
+            this.cacheName = cacheName;
+        }
+
+        /** */
+        private Converter() {
+            this(null);
+        }
+
+        /**
+         * Gets and converts values referenced by sequential keys, e.g. {@code key1...keyN}.
+         *
+         * @param type Optional value type.
+         * @param keyPrefix Key prefix, e.g. {@code key} for {@code key1...keyN}.
+         * @param params Parameters map.
+         * @return Values.
 
 Review comment:
   Done

----------------------------------------------------------------
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

[GitHub] [ignite] alex-plekhanov commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST

Posted by GitBox <gi...@apache.org>.
alex-plekhanov commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST
URL: https://github.com/apache/ignite/pull/7648#discussion_r409667359
 
 

 ##########
 File path: modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java
 ##########
 @@ -2878,6 +3134,341 @@ public void ref(CircularRef ref) {
         }
     }
 
+    /** */
+    @JsonInclude(JsonInclude.Include.NON_NULL)
+    @SuppressWarnings("AssignmentOrReturnOfFieldWithMutableType")
+    public static class OuterClass {
+        /** */
+        private long id;
+
+        /** */
+        private String name;
+
+        /** */
+        private double doubleVal;
+
+        /** */
+        private Boolean optional;
+
+        /** */
+        private ArrayList<Integer> list;
+
+        /** */
+        private Timestamp timestamp;
+
+        /** */
+        private long[] longs;
+
+        /** */
+        OuterClass() {
+            // No-op.
+        }
+
+        /** */
+        OuterClass(long id, String name, double doubleVal, List<Integer> list, @Nullable Boolean optional) {
+            this.id = id;
+            this.name = name;
+            this.doubleVal = doubleVal;
+            this.list = new ArrayList<>(list);
+            this.optional = optional;
+        }
+
+        /** */
+        public long getId() {
+            return id;
+        }
+
+        /** */
+        public String getName() {
+            return name;
+        }
+
+        /** */
+        public Boolean getOptional() {
+            return optional;
+        }
+
+        /** */
+        public double getDoubleVal() {
+            return doubleVal;
+        }
+
+        /** */
+        public ArrayList<Integer> getList() {
+            return list;
+        }
+
+        /** */
+        public Timestamp getTimestamp() {
+            return timestamp;
+        }
+
+        /** */
+        public long[] getLongs() {
+            return longs;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean equals(Object o) {
+            if (this == o)
+                return true;
+            if (o == null || getClass() != o.getClass())
+                return false;
+            OuterClass aClass = (OuterClass)o;
+            return id == aClass.id &&
+                Double.compare(aClass.doubleVal, doubleVal) == 0 &&
+                Objects.equals(name, aClass.name) &&
+                Objects.equals(optional, aClass.optional) &&
+                Objects.equals(list, aClass.list) &&
+                Objects.equals(timestamp, aClass.timestamp) &&
+                Arrays.equals(longs, aClass.longs);
+        }
+
+        /** {@inheritDoc} */
+        @Override public int hashCode() {
+            return Objects.hash(id, name, optional, doubleVal, list, timestamp, longs);
+        }
+
+        /** {@inheritDoc} */
+        @Override public String toString() {
+            return "OuterClass{" +
+                "id=" + id +
+                ", name='" + name + '\'' +
+                ", doubleVal=" + doubleVal +
+                ", optional=" + optional +
+                ", list=" + list +
+                ", timestamp=" + timestamp +
+                ", bytes=" + Arrays.toString(longs) +
+                '}';
+        }
+    }
+
+    /** */
+    public enum COLOR {
 
 Review comment:
   `Color` + comments for each item by codestyle

----------------------------------------------------------------
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

[GitHub] [ignite] xtern commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST

Posted by GitBox <gi...@apache.org>.
xtern commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST
URL: https://github.com/apache/ignite/pull/7648#discussion_r409870613
 
 

 ##########
 File path: modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
 ##########
 @@ -157,16 +160,16 @@
      *
      * @param hnd Handler.
      * @param authChecker Authentication checking closure.
-     * @param log Logger.
+     * @param ctx Kernal context.
      */
-    GridJettyRestHandler(GridRestProtocolHandler hnd, IgniteClosure<String, Boolean> authChecker, IgniteLogger log) {
+    GridJettyRestHandler(GridRestProtocolHandler hnd, IgniteClosure<String, Boolean> authChecker, GridKernalContext ctx) {
 
 Review comment:
   Fixed, thanks.

----------------------------------------------------------------
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

[GitHub] [ignite] xtern commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST

Posted by GitBox <gi...@apache.org>.
xtern commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST
URL: https://github.com/apache/ignite/pull/7648#discussion_r409838950
 
 

 ##########
 File path: modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
 ##########
 @@ -157,16 +160,15 @@
      *
      * @param hnd Handler.
      * @param authChecker Authentication checking closure.
-     * @param log Logger.
+     * @param ctx Kernal context.
      */
-    GridJettyRestHandler(GridRestProtocolHandler hnd, IgniteClosure<String, Boolean> authChecker, IgniteLogger log) {
+    GridJettyRestHandler(GridRestProtocolHandler hnd, IgniteClosure<String, Boolean> authChecker, GridKernalContext ctx) {
         assert hnd != null;
-        assert log != null;
 
 Review comment:
   Done

----------------------------------------------------------------
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

[GitHub] [ignite] xtern commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST

Posted by GitBox <gi...@apache.org>.
xtern commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST
URL: https://github.com/apache/ignite/pull/7648#discussion_r410150367
 
 

 ##########
 File path: modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/IgniteBinaryObjectJsonDeserializer.java
 ##########
 @@ -0,0 +1,344 @@
+/*
+ * 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.ignite.internal.processors.rest.protocols.http.jetty;
+
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.ObjectCodec;
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.JsonDeserializer;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.JsonNodeType;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.binary.BinaryObjectBuilder;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryType;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.binary.BinaryClassDescriptor;
+import org.apache.ignite.internal.binary.BinaryFieldMetadata;
+import org.apache.ignite.internal.binary.BinaryObjectImpl;
+import org.apache.ignite.internal.binary.BinaryTypeImpl;
+import org.apache.ignite.internal.binary.BinaryUtils;
+import org.apache.ignite.internal.binary.GridBinaryMarshaller;
+import org.apache.ignite.internal.processors.query.QueryTypeDescriptorImpl;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * JSON deserializer into the Ignite binary object.
+ */
+public class IgniteBinaryObjectJsonDeserializer extends JsonDeserializer<BinaryObjectImpl> {
+    /** Property name to set binary type name. */
+    public static final String BINARY_TYPE_PROPERTY = "binaryTypeName";
+
+    /** Property name to set cache name. */
+    public static final String CACHE_NAME_PROPERTY = "cacheName";
+
+    /** Kernal context. */
+    private final GridKernalContext ctx;
+
+    /**
+     * @param ctx Kernal context.
+     */
+    public IgniteBinaryObjectJsonDeserializer(GridKernalContext ctx) {
+        assert ctx != null;
+
+        this.ctx = ctx;
+    }
+
+    /** {@inheritDoc} */
+    @Override public BinaryObjectImpl deserialize(JsonParser parser, DeserializationContext dCtx) throws IOException {
+        String type = (String)dCtx.findInjectableValue(BINARY_TYPE_PROPERTY, null, null);
+        String cacheName = (String)dCtx.findInjectableValue(CACHE_NAME_PROPERTY, null, null);
+
+        assert type != null;
+
+        if (ctx.marshallerContext().isSystemType(type))
+            throw new IllegalArgumentException("Cannot make binary object [type=" + type + "]");
+
+        ObjectCodec mapper = parser.getCodec();
+        JsonNode jsonTree = mapper.readTree(parser);
+
+        return (BinaryObjectImpl)deserialize0(cacheName, type, jsonTree, mapper);
+    }
+
+    /**
+     * @param cacheName Cache name.
+     * @param type Type name.
+     * @param node JSON node.
+     * @param mapper JSON object mapper.
+     * @return Deserialized object.
+     * @throws IOException In case of error.
+     */
+    private Object deserialize0(String cacheName, String type, JsonNode node, ObjectCodec mapper) throws IOException {
+        if (ctx.marshallerContext().isSystemType(type)) {
+            Class<?> cls = IgniteUtils.classForName(type, null);
+
+            if (cls != null)
+                return mapper.treeToValue(node, cls);
+        }
+
+        BinaryType binType = ctx.cacheObjects().binary().type(type);
+
+        Deserializer deserializer = binType instanceof BinaryTypeImpl ?
+            new BinaryTypeDeserializer(cacheName, (BinaryTypeImpl)binType, mapper) :
+            new Deserializer(cacheName, type, mapper);
+
+        return deserializer.deserialize(node);
+    }
+
+    /**
+     * JSON deserializer creates a new binary type using JSON data types.
+     */
+    private class Deserializer {
+        /** New binary type name. */
+        private final String type;
+
+        /** Cache query meta. */
+        protected final Map<String, Class<?>> qryFields;
+
+        /** Cache name. */
+        protected final String cacheName;
+
+        /** JSON object mapper. */
+        protected final ObjectCodec mapper;
+
+        /**
+         * @param cacheName Cache name.
+         * @param type Type name.
+         * @param mapper JSON object mapper.
+         */
+        public Deserializer(@Nullable String cacheName, String type, ObjectCodec mapper) {
+            this.type = type;
+            this.mapper = mapper;
+            this.cacheName = cacheName;
+
+            qryFields = qryFields();
+        }
+
+        /**
+         * @return Mapping from field name to its type.
+         */
+        private Map<String, Class<?>> qryFields() {
+            if (ctx.query().moduleEnabled()) {
+                QueryTypeDescriptorImpl desc = ctx.query().typeDescriptor(cacheName, type);
+
+                if (desc != null)
+                    return desc.fields();
+            }
+
+            return Collections.emptyMap();
+        }
+
+        /**
+         * Deserialize JSON tree.
+         *
+         * @param tree JSON tree node.
+         * @return Binary object.
+         * @throws IOException In case of error.
+         */
+        public BinaryObject deserialize(JsonNode tree) throws IOException {
+            return binaryValue(type, tree);
+        }
+
+        /**
+         * @param type Ignite binary type name.
+         * @param tree JSON tree node.
+         * @return Binary object.
+         * @throws IOException In case of error.
+         */
+        private BinaryObject binaryValue(String type, JsonNode tree) throws IOException {
+            BinaryObjectBuilder builder = ctx.cacheObjects().builder(type);
+
+            Iterator<Map.Entry<String, JsonNode>> itr = tree.fields();
+
+            while (itr.hasNext()) {
+                Map.Entry<String, JsonNode> entry = itr.next();
+
+                String field = entry.getKey();
+                Object val = readValue(field, entry.getValue());
+
+                builder.setField(field, val);
+            }
+
+            return builder.build();
+        }
+
+        /**
+         * @param field Field name.
+         * @param jsonNode JSON node.
+         * @return value.
+         * @throws IOException In case of error.
+         */
+        @Nullable protected Object readValue(String field, JsonNode jsonNode) throws IOException {
+            JsonNodeType nodeType = jsonNode.getNodeType();
+
+            if (nodeType == JsonNodeType.BINARY)
+                return jsonNode.binaryValue();
+
+            if (nodeType == JsonNodeType.BOOLEAN)
+                return jsonNode.booleanValue();
+
+            Class<?> cls = qryFields.get(field.toUpperCase());
 
 Review comment:
   Done.

----------------------------------------------------------------
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

[GitHub] [ignite] NSAmelchev commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST

Posted by GitBox <gi...@apache.org>.
NSAmelchev commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST
URL: https://github.com/apache/ignite/pull/7648#discussion_r409885676
 
 

 ##########
 File path: modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java
 ##########
 @@ -2778,6 +2991,87 @@ protected void initCache() {
         assertEquals(2, personCache.query(qry).getAll().size());
     }
 
+    /**
+     * @param cacheName Cache name.
+     * @param key Cache key.
+     * @param obj Cache value.
+     * @throws Exception If failed.
+     */
+    private void putObject(String cacheName, String key, Object obj) throws Exception {
+        putObject(cacheName, key, obj, obj.getClass().getName());
+    }
+
+    /**
+     * @param cacheName Cache name.
+     * @param key Cache key.
+     * @param obj Cache value.
+     * @param type Cache value type.
+     * @throws Exception If failed.
+     */
+    private void putObject(String cacheName, String key, Object obj, String type) throws Exception {
+        String json = JSON_MAPPER.writeValueAsString(obj);
+
+        info("Put: " + json);
+
+        String ret = content(cacheName, GridRestCommand.CACHE_PUT,
+            "keyType", "int",
+            "key", key,
+            "valueType", type,
+            "val", json
+        );
+
+        info("Put command result: " + ret);
+
+        assertResponseSucceeded(ret, false);
+    }
+
+    /**
+     * @param cacheName Cache name.
+     * @param key Cache key.
+     * @param cls Cache value class.
+     * @param <T> Cache value type.
+     * @return Deserialized object of type {@code T}.
+     * @throws Exception If failed.
+     */
+    private <T> T getObject(String cacheName, String key, Class<T> cls) throws Exception {
+        String ret = content(cacheName, GridRestCommand.CACHE_GET, "keyType", "int", "key", key);
+
+        info("Get command result: " + ret);
+
+        JsonNode res = assertResponseSucceeded(ret, false);
+
+        return JSON_MAPPER.treeToValue(res, cls);
+    }
+
+    /**
+     * @param cacheName Cache name.
+     * @param params Query parameters.
+     * @return Json query result.
+     * @throws Exception If failed.
+     */
+    private JsonNode queryObject(String cacheName, String ... params) throws Exception {
 
 Review comment:
   Unnecessary whitespace `String ...`

----------------------------------------------------------------
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

[GitHub] [ignite] xtern commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST

Posted by GitBox <gi...@apache.org>.
xtern commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST
URL: https://github.com/apache/ignite/pull/7648#discussion_r409891652
 
 

 ##########
 File path: modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/IgniteBinaryObjectJsonDeserializer.java
 ##########
 @@ -0,0 +1,342 @@
+/*
+ * 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.ignite.internal.processors.rest.protocols.http.jetty;
+
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.ObjectCodec;
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.JsonDeserializer;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.JsonNodeType;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.binary.BinaryObjectBuilder;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryType;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.binary.BinaryClassDescriptor;
+import org.apache.ignite.internal.binary.BinaryFieldMetadata;
+import org.apache.ignite.internal.binary.BinaryObjectImpl;
+import org.apache.ignite.internal.binary.BinaryTypeImpl;
+import org.apache.ignite.internal.binary.BinaryUtils;
+import org.apache.ignite.internal.binary.GridBinaryMarshaller;
+import org.apache.ignite.internal.processors.query.QueryTypeDescriptorImpl;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * JSON deserializer into the Ignite binary object.
+ */
+public class IgniteBinaryObjectJsonDeserializer extends JsonDeserializer<BinaryObjectImpl> {
+    /** Property name to set binary type name. */
+    public static final String BINARY_TYPE_PROPERTY = "binaryTypeName";
+
+    /** Property name to set cache name. */
+    public static final String CACHE_NAME_PROPERTY = "cacheName";
+
+    /** Kernal context. */
+    private final GridKernalContext ctx;
+
+    /**
+     * @param ctx Kernal context.
+     */
+    public IgniteBinaryObjectJsonDeserializer(GridKernalContext ctx) {
+        assert ctx != null;
+
+        this.ctx = ctx;
+    }
+
+    /** {@inheritDoc} */
+    @Override public BinaryObjectImpl deserialize(JsonParser parser, DeserializationContext dCtx) throws IOException {
+        String type = (String)dCtx.findInjectableValue(BINARY_TYPE_PROPERTY, null, null);
+        String cacheName = (String)dCtx.findInjectableValue(CACHE_NAME_PROPERTY, null, null);
+
+        assert type != null;
+
+        if (ctx.marshallerContext().isSystemType(type))
+            throw new IllegalArgumentException("Cannot make binary object [type=" + type + "]");
+
+        ObjectCodec mapper = parser.getCodec();
+        JsonNode jsonTree = mapper.readTree(parser);
+
+        return (BinaryObjectImpl)deserialize0(cacheName, type, jsonTree, mapper);
+    }
+
+    /**
+     * @param cacheName Cache name.
+     * @param type Type name.
+     * @param node JSON node.
+     * @param mapper JSON object mapper.
+     * @return Deserialized object.
+     * @throws IOException In case of error.
+     */
+    private Object deserialize0(String cacheName, String type, JsonNode node, ObjectCodec mapper) throws IOException {
+        if (ctx.marshallerContext().isSystemType(type)) {
+            Class<?> cls = IgniteUtils.classForName(type, null);
+
+            if (cls != null)
+                return mapper.treeToValue(node, cls);
+        }
+
+        BinaryType binType = ctx.cacheObjects().binary().type(type);
+
+        Deserializer deserializer = binType instanceof BinaryTypeImpl ?
+            new BinaryTypeDeserializer(cacheName, (BinaryTypeImpl)binType, mapper) :
+            new Deserializer(cacheName, type, mapper);
+
+        return deserializer.deserialize(node);
+    }
+
+    /**
+     * JSON deserializer creates a new binary type using JSON data types.
+     */
+    private class Deserializer {
+        /** New binary type name. */
+        private final String type;
+
+        /** Cache query meta. */
+        protected final Map<String, Class<?>> qryFields;
+
+        /** Cache name. */
+        protected final String cacheName;
+
+        /** JSON object mapper. */
+        protected final ObjectCodec mapper;
+
+        /**
+         * @param cacheName Cache name.
+         * @param type Type name.
+         * @param mapper JSON object mapper.
+         */
+        public Deserializer(@Nullable String cacheName, String type, ObjectCodec mapper) {
+            this.type = type;
+            this.mapper = mapper;
+            this.cacheName = cacheName;
+
+            qryFields = qryFields();
+        }
+
+        /**
+         * @return Mapping from field name to its type.
+         */
+        private Map<String, Class<?>> qryFields() {
+            if (ctx.query().moduleEnabled()) {
+                QueryTypeDescriptorImpl desc = ctx.query().typeDescriptor(cacheName, type);
+
+                if (desc != null)
+                    return desc.fields();
+            }
+
+            return Collections.emptyMap();
+        }
+
+        /**
+         * Deserialize JSON tree.
+         *
+         * @param tree JSON tree node.
+         * @return Binary object.
+         * @throws IOException In case of error.
+         */
+        public BinaryObject deserialize(JsonNode tree) throws IOException {
+            return binaryValue(type, tree);
+        }
+
+        /**
+         * @param type Ignite binary type name.
+         * @param tree JSON tree node.
+         * @return Binary object.
+         * @throws IOException In case of error.
+         */
+        private BinaryObject binaryValue(String type, JsonNode tree) throws IOException {
+            BinaryObjectBuilder builder = ctx.cacheObjects().builder(type);
+
+            Iterator<Map.Entry<String, JsonNode>> itr = tree.fields();
+
+            while (itr.hasNext()) {
+                Map.Entry<String, JsonNode> entry = itr.next();
+
+                String field = entry.getKey();
+                Object val = readValue(field, entry.getValue());
+
+                builder.setField(field, val);
+            }
+
+            return builder.build();
+        }
+
+        /**
+         * @param field Field name.
+         * @param jsonNode JSON node.
+         * @return value.
+         * @throws IOException In case of error.
+         */
+        protected Object readValue(String field, JsonNode jsonNode) throws IOException {
+            JsonNodeType nodeType = jsonNode.getNodeType();
+
+            if (nodeType == JsonNodeType.BINARY)
+                return jsonNode.binaryValue();
+
+            if (nodeType == JsonNodeType.BOOLEAN)
+                return jsonNode.booleanValue();
+
+            Class<?> cls = qryFields.get(field.toUpperCase());
+
+            if (cls != null)
+                return mapper.treeToValue(jsonNode, cls);
+
+            switch (nodeType) {
+                case ARRAY:
+                    List<Object> list = new ArrayList<>(jsonNode.size());
+                    Iterator<JsonNode> itr = jsonNode.elements();
+
+                    while (itr.hasNext())
+                        list.add(readValue(field, itr.next()));
+
+                    return list;
+
+                case NUMBER:
+                    return jsonNode.numberValue();
+
+                case OBJECT:
+                    return mapper.treeToValue(jsonNode, cls);
+
+                case STRING:
+                    return jsonNode.asText();
+
+                default:
+                    return null;
+            }
+        }
+    }
+
+    /**
+     * JSON deserializer using the existing Ignite binary type.
+     */
+    private class BinaryTypeDeserializer extends Deserializer {
+        /** Binary type. */
+        private final BinaryTypeImpl binType;
+
+        /** Binary class descriptor. */
+        private final BinaryClassDescriptor binClsDesc;
+
+        /**
+         * @param cacheName Cache name.
+         * @param binaryType Binary type.
+         * @param mapper JSON object mapper.
+         */
+        public BinaryTypeDeserializer(@Nullable String cacheName, BinaryTypeImpl binaryType, ObjectCodec mapper) {
+            super(cacheName, binaryType.typeName(), mapper);
+
+            binType = binaryType;
+            binClsDesc = binaryClassDescriptor();
+        }
+
+        /** {@inheritDoc} */
+        @Override public BinaryObject deserialize(JsonNode tree) throws IOException {
+            BinaryObjectBuilder builder = ctx.cacheObjects().builder(binType.typeName());
+            Map<String, BinaryFieldMetadata> metas = binType.metadata().fieldsMap();
+
+            Iterator<Map.Entry<String, JsonNode>> itr = tree.fields();
+
+            while (itr.hasNext()) {
+                Map.Entry<String, JsonNode> entry = itr.next();
+
+                String field = entry.getKey();
+                JsonNode node = tree.get(field);
+                BinaryFieldMetadata meta = metas.get(field);
+
+                Object val = meta != null ?
+                    readValue(meta.typeId(), field, node, binType) : readValue(field, node);
+
+                builder.setField(field, val);
+            }
+
+            return builder.build();
+        }
+
+        /**
+         * Extract and cast JSON node value into required object format.
+         *
+         * @param type Field type.
+         * @param field Field name.
+         * @param node JSON node.
+         * @param parentType Parent type.
+         * @return Extracted value.
+         * @throws IOException if failed.
+         */
+        private Object readValue(int type, String field, JsonNode node, BinaryTypeImpl parentType) throws IOException {
+            Class<?> baseCls;
+
+            switch (type) {
+                case GridBinaryMarshaller.MAP:
+                    baseCls = Map.class;
+
+                    break;
+                case GridBinaryMarshaller.OBJ_ARR:
+                case GridBinaryMarshaller.COL:
+                case GridBinaryMarshaller.OBJ:
+                case GridBinaryMarshaller.ENUM:
+                    baseCls = fieldClass(field);
+
+                    if (baseCls == null)
+                        return readValue(field, node);
+
+                    break;
+                default:
+                    baseCls = BinaryUtils.FLAG_TO_CLASS.get((byte)type);
+            }
+
+            if (baseCls != null)
+                return mapper.treeToValue(node, baseCls);
+
+            return deserialize0(cacheName, parentType.fieldTypeName(field), node, mapper);
+        }
+
+        /**
+         * @return Class descriptor for current binary type or {@code null} if the class was not found.
+         */
+        private @Nullable BinaryClassDescriptor binaryClassDescriptor() {
+            try {
+                return binType.context().descriptorForTypeId(false, binType.typeId(),null,false);
 
 Review comment:
   done

----------------------------------------------------------------
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

[GitHub] [ignite] alex-plekhanov commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST

Posted by GitBox <gi...@apache.org>.
alex-plekhanov commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST
URL: https://github.com/apache/ignite/pull/7648#discussion_r410120729
 
 

 ##########
 File path: modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/IgniteBinaryObjectJsonDeserializer.java
 ##########
 @@ -0,0 +1,344 @@
+/*
+ * 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.ignite.internal.processors.rest.protocols.http.jetty;
+
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.ObjectCodec;
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.JsonDeserializer;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.JsonNodeType;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.binary.BinaryObjectBuilder;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryType;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.binary.BinaryClassDescriptor;
+import org.apache.ignite.internal.binary.BinaryFieldMetadata;
+import org.apache.ignite.internal.binary.BinaryObjectImpl;
+import org.apache.ignite.internal.binary.BinaryTypeImpl;
+import org.apache.ignite.internal.binary.BinaryUtils;
+import org.apache.ignite.internal.binary.GridBinaryMarshaller;
+import org.apache.ignite.internal.processors.query.QueryTypeDescriptorImpl;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * JSON deserializer into the Ignite binary object.
+ */
+public class IgniteBinaryObjectJsonDeserializer extends JsonDeserializer<BinaryObjectImpl> {
+    /** Property name to set binary type name. */
+    public static final String BINARY_TYPE_PROPERTY = "binaryTypeName";
+
+    /** Property name to set cache name. */
+    public static final String CACHE_NAME_PROPERTY = "cacheName";
+
+    /** Kernal context. */
+    private final GridKernalContext ctx;
+
+    /**
+     * @param ctx Kernal context.
+     */
+    public IgniteBinaryObjectJsonDeserializer(GridKernalContext ctx) {
+        assert ctx != null;
+
+        this.ctx = ctx;
+    }
+
+    /** {@inheritDoc} */
+    @Override public BinaryObjectImpl deserialize(JsonParser parser, DeserializationContext dCtx) throws IOException {
+        String type = (String)dCtx.findInjectableValue(BINARY_TYPE_PROPERTY, null, null);
+        String cacheName = (String)dCtx.findInjectableValue(CACHE_NAME_PROPERTY, null, null);
+
+        assert type != null;
+
+        if (ctx.marshallerContext().isSystemType(type))
+            throw new IllegalArgumentException("Cannot make binary object [type=" + type + "]");
+
+        ObjectCodec mapper = parser.getCodec();
+        JsonNode jsonTree = mapper.readTree(parser);
+
+        return (BinaryObjectImpl)deserialize0(cacheName, type, jsonTree, mapper);
+    }
+
+    /**
+     * @param cacheName Cache name.
+     * @param type Type name.
+     * @param node JSON node.
+     * @param mapper JSON object mapper.
+     * @return Deserialized object.
+     * @throws IOException In case of error.
+     */
+    private Object deserialize0(String cacheName, String type, JsonNode node, ObjectCodec mapper) throws IOException {
+        if (ctx.marshallerContext().isSystemType(type)) {
+            Class<?> cls = IgniteUtils.classForName(type, null);
+
+            if (cls != null)
+                return mapper.treeToValue(node, cls);
+        }
+
+        BinaryType binType = ctx.cacheObjects().binary().type(type);
+
+        Deserializer deserializer = binType instanceof BinaryTypeImpl ?
+            new BinaryTypeDeserializer(cacheName, (BinaryTypeImpl)binType, mapper) :
+            new Deserializer(cacheName, type, mapper);
+
+        return deserializer.deserialize(node);
+    }
+
+    /**
+     * JSON deserializer creates a new binary type using JSON data types.
+     */
+    private class Deserializer {
+        /** New binary type name. */
+        private final String type;
+
+        /** Cache query meta. */
+        protected final Map<String, Class<?>> qryFields;
+
+        /** Cache name. */
+        protected final String cacheName;
+
+        /** JSON object mapper. */
+        protected final ObjectCodec mapper;
+
+        /**
+         * @param cacheName Cache name.
+         * @param type Type name.
+         * @param mapper JSON object mapper.
+         */
+        public Deserializer(@Nullable String cacheName, String type, ObjectCodec mapper) {
+            this.type = type;
+            this.mapper = mapper;
+            this.cacheName = cacheName;
+
+            qryFields = qryFields();
+        }
+
+        /**
+         * @return Mapping from field name to its type.
+         */
+        private Map<String, Class<?>> qryFields() {
+            if (ctx.query().moduleEnabled()) {
+                QueryTypeDescriptorImpl desc = ctx.query().typeDescriptor(cacheName, type);
+
+                if (desc != null)
+                    return desc.fields();
+            }
+
+            return Collections.emptyMap();
+        }
+
+        /**
+         * Deserialize JSON tree.
+         *
+         * @param tree JSON tree node.
+         * @return Binary object.
+         * @throws IOException In case of error.
+         */
+        public BinaryObject deserialize(JsonNode tree) throws IOException {
+            return binaryValue(type, tree);
+        }
+
+        /**
+         * @param type Ignite binary type name.
+         * @param tree JSON tree node.
+         * @return Binary object.
+         * @throws IOException In case of error.
+         */
+        private BinaryObject binaryValue(String type, JsonNode tree) throws IOException {
+            BinaryObjectBuilder builder = ctx.cacheObjects().builder(type);
+
+            Iterator<Map.Entry<String, JsonNode>> itr = tree.fields();
+
+            while (itr.hasNext()) {
+                Map.Entry<String, JsonNode> entry = itr.next();
+
+                String field = entry.getKey();
+                Object val = readValue(field, entry.getValue());
+
+                builder.setField(field, val);
+            }
+
+            return builder.build();
+        }
+
+        /**
+         * @param field Field name.
+         * @param jsonNode JSON node.
+         * @return value.
+         * @throws IOException In case of error.
+         */
+        @Nullable protected Object readValue(String field, JsonNode jsonNode) throws IOException {
+            JsonNodeType nodeType = jsonNode.getNodeType();
+
+            if (nodeType == JsonNodeType.BINARY)
+                return jsonNode.binaryValue();
+
+            if (nodeType == JsonNodeType.BOOLEAN)
+                return jsonNode.booleanValue();
+
+            Class<?> cls = qryFields.get(field.toUpperCase());
 
 Review comment:
   Use `QueryUtils#normalizeObjectName` instead of `toUpperCase`

----------------------------------------------------------------
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

[GitHub] [ignite] alex-plekhanov commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST

Posted by GitBox <gi...@apache.org>.
alex-plekhanov commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST
URL: https://github.com/apache/ignite/pull/7648#discussion_r409676108
 
 

 ##########
 File path: modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java
 ##########
 @@ -2878,6 +3134,341 @@ public void ref(CircularRef ref) {
         }
     }
 
+    /** */
+    @JsonInclude(JsonInclude.Include.NON_NULL)
+    @SuppressWarnings("AssignmentOrReturnOfFieldWithMutableType")
+    public static class OuterClass {
+        /** */
+        private long id;
+
+        /** */
+        private String name;
+
+        /** */
+        private double doubleVal;
+
+        /** */
+        private Boolean optional;
+
+        /** */
+        private ArrayList<Integer> list;
+
+        /** */
+        private Timestamp timestamp;
+
+        /** */
+        private long[] longs;
+
+        /** */
+        OuterClass() {
+            // No-op.
+        }
+
+        /** */
+        OuterClass(long id, String name, double doubleVal, List<Integer> list, @Nullable Boolean optional) {
+            this.id = id;
+            this.name = name;
+            this.doubleVal = doubleVal;
+            this.list = new ArrayList<>(list);
+            this.optional = optional;
+        }
+
+        /** */
+        public long getId() {
+            return id;
+        }
+
+        /** */
+        public String getName() {
+            return name;
+        }
+
+        /** */
+        public Boolean getOptional() {
+            return optional;
+        }
+
+        /** */
+        public double getDoubleVal() {
+            return doubleVal;
+        }
+
+        /** */
+        public ArrayList<Integer> getList() {
+            return list;
+        }
+
+        /** */
+        public Timestamp getTimestamp() {
+            return timestamp;
+        }
+
+        /** */
+        public long[] getLongs() {
+            return longs;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean equals(Object o) {
+            if (this == o)
+                return true;
+            if (o == null || getClass() != o.getClass())
+                return false;
+            OuterClass aClass = (OuterClass)o;
+            return id == aClass.id &&
+                Double.compare(aClass.doubleVal, doubleVal) == 0 &&
+                Objects.equals(name, aClass.name) &&
+                Objects.equals(optional, aClass.optional) &&
+                Objects.equals(list, aClass.list) &&
+                Objects.equals(timestamp, aClass.timestamp) &&
+                Arrays.equals(longs, aClass.longs);
+        }
+
+        /** {@inheritDoc} */
+        @Override public int hashCode() {
+            return Objects.hash(id, name, optional, doubleVal, list, timestamp, longs);
+        }
+
+        /** {@inheritDoc} */
+        @Override public String toString() {
+            return "OuterClass{" +
+                "id=" + id +
+                ", name='" + name + '\'' +
+                ", doubleVal=" + doubleVal +
+                ", optional=" + optional +
+                ", list=" + list +
+                ", timestamp=" + timestamp +
+                ", bytes=" + Arrays.toString(longs) +
+                '}';
+        }
+    }
+
+    /** */
+    public enum COLOR {
+        RED,
+        GREEN,
+        BLUE
+    }
+
+    /** Complex entity. */
+    @SuppressWarnings({"InnerClassMayBeStatic", "AssignmentOrReturnOfFieldWithMutableType"})
+    static class Complex implements Serializable {
+        /** */
+        @QuerySqlField(index = true)
+        private Integer id;
+
+        /** */
+        @QuerySqlField
+        private String string;
 
 Review comment:
   Abbreviation should be used

----------------------------------------------------------------
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

[GitHub] [ignite] NSAmelchev commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST

Posted by GitBox <gi...@apache.org>.
NSAmelchev commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST
URL: https://github.com/apache/ignite/pull/7648#discussion_r409864502
 
 

 ##########
 File path: modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
 ##########
 @@ -1106,6 +1016,139 @@ private boolean credentials(Map<String, Object> params, String userParam, String
         return null;
     }
 
+    /** */
 
 Review comment:
   Add javadoc, please

----------------------------------------------------------------
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

[GitHub] [ignite] NSAmelchev commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST

Posted by GitBox <gi...@apache.org>.
NSAmelchev commented on a change in pull request #7648: IGNITE-12857 Put custom objects via REST
URL: https://github.com/apache/ignite/pull/7648#discussion_r409863502
 
 

 ##########
 File path: modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
 ##########
 @@ -157,16 +160,16 @@
      *
      * @param hnd Handler.
      * @param authChecker Authentication checking closure.
-     * @param log Logger.
+     * @param ctx Kernal context.
      */
-    GridJettyRestHandler(GridRestProtocolHandler hnd, IgniteClosure<String, Boolean> authChecker, IgniteLogger log) {
+    GridJettyRestHandler(GridRestProtocolHandler hnd, IgniteClosure<String, Boolean> authChecker, GridKernalContext ctx) {
 
 Review comment:
   Too long line

----------------------------------------------------------------
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