ibessonov commented on a change in pull request #72:
URL: https://github.com/apache/ignite-3/pull/72#discussion_r598571783



##########
File path: 
modules/rest/src/main/java/org/apache/ignite/rest/presentation/json/JsonConverter.java
##########
@@ -35,6 +52,213 @@
         return gson.toJson(obj);
     }
 
+    /** */
+    public static ConfigurationVisitor<JsonElement> jsonVisitor() {
+        return new ConfigurationVisitor<JsonElement>() {
+            /** */
+            private final Deque<JsonObject> jsonObjectsStack = new 
ArrayDeque<>();
+
+            /** {@inheritDoc} */
+            @Override public JsonElement visitLeafNode(String key, 
Serializable val) {
+                JsonElement jsonLeaf = toJsonLeaf(val);
+
+                if (!jsonObjectsStack.isEmpty())
+                    jsonObjectsStack.peek().add(key, jsonLeaf);
+
+                return jsonLeaf;
+            }
+
+            /** {@inheritDoc} */
+            @Override public JsonElement visitInnerNode(String key, InnerNode 
node) {
+                JsonObject innerJsonNode = new JsonObject();
+
+                jsonObjectsStack.push(innerJsonNode);
+
+                node.traverseChildren(this);
+
+                jsonObjectsStack.pop();
+
+                if (!jsonObjectsStack.isEmpty())
+                    jsonObjectsStack.peek().add(key, innerJsonNode);
+
+                return innerJsonNode;
+            }
+
+            /** {@inheritDoc} */
+            @Override public <N extends InnerNode> JsonElement 
visitNamedListNode(String key, NamedListNode<N> node) {
+                JsonObject namedListJsonNode = new JsonObject();
+
+                jsonObjectsStack.push(namedListJsonNode);
+
+                for (String subkey : node.namedListKeys())
+                    node.get(subkey).accept(subkey, this);
+
+                jsonObjectsStack.pop();
+
+                if (!jsonObjectsStack.isEmpty())
+                    jsonObjectsStack.peek().add(key, namedListJsonNode);
+
+                return namedListJsonNode;
+            }
+
+            /** */
+            @NotNull private JsonElement toJsonLeaf(Serializable val) {
+                if (val == null)
+                    return JsonNull.INSTANCE;
+
+                Class<? extends Serializable> valClass = val.getClass();

Review comment:
       I'm not sure that we still follow abbreviation recommendations for 3.0 
so let's leave it as it is for now




-- 
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:
[email protected]


Reply via email to