streams-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (STREAMS-549) Bug in PropertyUtil.mergeProperties
Date Wed, 08 Nov 2017 01:38:01 GMT

    [ https://issues.apache.org/jira/browse/STREAMS-549?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16243241#comment-16243241
] 

ASF GitHub Bot commented on STREAMS-549:
----------------------------------------

steveblackmon closed pull request #403: STREAMS-549: Bug in PropertyUtil.mergeProperties
URL: https://github.com/apache/streams/pull/403
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/streams-util/src/main/java/org/apache/streams/util/PropertyUtil.java b/streams-util/src/main/java/org/apache/streams/util/PropertyUtil.java
index 93ff76af6..63678f68b 100644
--- a/streams-util/src/main/java/org/apache/streams/util/PropertyUtil.java
+++ b/streams-util/src/main/java/org/apache/streams/util/PropertyUtil.java
@@ -128,6 +128,10 @@ public static ObjectNode mergeProperties(ObjectNode content, ObjectNode
parent)
       if( merged.get(fieldId) != null ) {
         if( merged.get(fieldId).getNodeType().equals(JsonNodeType.OBJECT)) {
           merged.put(fieldId, mergeProperties(field.getValue().deepCopy(), (ObjectNode)merged.get(fieldId)));
+        } else if ( merged.get(fieldId).getNodeType().equals(JsonNodeType.ARRAY)) {
+          merged.put(fieldId, mergeArrays(((ArrayNode)field.getValue()), ((ArrayNode)merged.get(fieldId))));
+        } else {
+          merged.put(fieldId, content.get(fieldId));
         }
       } else {
         merged.put(fieldId, content.get(fieldId));
@@ -136,4 +140,14 @@ public static ObjectNode mergeProperties(ObjectNode content, ObjectNode
parent)
     return merged;
   }
 
+  /**
+   * merge two arrays.
+   * @param content ArrayNode
+   * @param parent ArrayNode
+   * @return merged ArrayNode
+   */
+  private static ArrayNode mergeArrays(ArrayNode content, ArrayNode parent) {
+    return parent.deepCopy().addAll(content);
+  }
+
 }
diff --git a/streams-util/src/test/java/org/apache/streams/util/schema/test/PropertyUtilTest.java
b/streams-util/src/test/java/org/apache/streams/util/test/PropertyUtilTest.java
similarity index 84%
rename from streams-util/src/test/java/org/apache/streams/util/schema/test/PropertyUtilTest.java
rename to streams-util/src/test/java/org/apache/streams/util/test/PropertyUtilTest.java
index 062d719e1..fdba3f029 100644
--- a/streams-util/src/test/java/org/apache/streams/util/schema/test/PropertyUtilTest.java
+++ b/streams-util/src/test/java/org/apache/streams/util/test/PropertyUtilTest.java
@@ -16,13 +16,14 @@
  * under the License.
  */
 
-package org.apache.streams.util.schema.test;
+package org.apache.streams.util.test;
 
 import org.apache.streams.util.PropertyUtil;
 import org.apache.streams.util.schema.SchemaUtil;
 
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
 import com.fasterxml.jackson.databind.node.ObjectNode;
 import org.junit.Test;
 
@@ -56,13 +57,19 @@ public void testUnflattenObjectNode() throws Exception {
   public void testMergeProperties() throws Exception {
     ObjectMapper mapper = new ObjectMapper();
     ObjectNode left = mapper.createObjectNode();
-    left.put("objectType", "post").putObject("actor").putObject("author").put("id", "authorId");
+    left.put("objectType", "post");
+    left.putArray("links").add("link1");
+    left.putObject("actor").put("id", "leftId").putObject("author").put("id", "authorId");
     ObjectNode right = mapper.createObjectNode();
-    right.putObject("actor").put("id", "actorId").putObject("image").put("url", "http://url.com");
+    right.putArray("links").add("link2");
+    right.putObject("actor").put("id", "rightId").putObject("image").put("url", "http://url.com");
     JsonNode merged = PropertyUtil.mergeProperties(left, right);
     assert( merged.has("objectType"));
     assert( merged.has("actor"));
+    assert( merged.has("links"));
+    assert( (merged.get("links")).size() == 2);
     assert( merged.get("actor").has("id"));
+    assert( merged.get("actor").get("id").asText().equals("leftId"));
     assert( merged.get("actor").has("author"));
     assert( merged.get("actor").get("author").has("id"));
     assert( merged.get("actor").has("image"));


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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


> Bug in PropertyUtil.mergeProperties
> -----------------------------------
>
>                 Key: STREAMS-549
>                 URL: https://issues.apache.org/jira/browse/STREAMS-549
>             Project: Streams
>          Issue Type: Bug
>            Reporter: Steve Blackmon
>            Assignee: Steve Blackmon
>   Original Estimate: 4h
>  Remaining Estimate: 4h
>
> ValueNodes should over-write even when present on the fallback



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message