You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by np...@apache.org on 2021/09/01 13:20:13 UTC

[sling-org-apache-sling-pipes] branch master updated: SLING-10773 make JsonPipe.valuePath's dynamic

This is an automated email from the ASF dual-hosted git repository.

npeltier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-pipes.git


The following commit(s) were added to refs/heads/master by this push:
     new 938a8d5  SLING-10773 make JsonPipe.valuePath's dynamic
938a8d5 is described below

commit 938a8d5a954bee9908e5e6a38c94b46246350f84
Author: Nicolas Peltier <np...@apache.org>
AuthorDate: Wed Sep 1 15:06:58 2021 +0200

    SLING-10773 make JsonPipe.valuePath's dynamic
---
 .../java/org/apache/sling/pipes/internal/inputstream/JsonPipe.java   | 4 ++--
 .../org/apache/sling/pipes/internal/inputstream/JsonPipeTest.java    | 5 +++++
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/apache/sling/pipes/internal/inputstream/JsonPipe.java b/src/main/java/org/apache/sling/pipes/internal/inputstream/JsonPipe.java
index 4165142..eb9d185 100644
--- a/src/main/java/org/apache/sling/pipes/internal/inputstream/JsonPipe.java
+++ b/src/main/java/org/apache/sling/pipes/internal/inputstream/JsonPipe.java
@@ -78,7 +78,7 @@ public class JsonPipe extends AbstractInputStreamPipe {
     boolean isRaw() {
         if (properties.containsKey(PN_RAW)) {
             Object raw = bindings.instantiateObject(properties.get(PN_RAW, String.class));
-            if (raw != null && raw instanceof Boolean) {
+            if (raw instanceof Boolean) {
                 return (Boolean) raw;
             }
             return Boolean.parseBoolean((String)raw);
@@ -105,7 +105,7 @@ public class JsonPipe extends AbstractInputStreamPipe {
                 } else {
                     String valuePath = properties.get(PN_VALUEPATH, String.class);
                     if (StringUtils.isNotBlank(valuePath)) {
-                        json = getValue(json, valuePath);
+                        json = getValue(json, bindings.instantiateExpression(valuePath));
                     }
                     if (isRaw() || !(json.getValueType() == ValueType.ARRAY || json.getValueType() == ValueType.OBJECT)) {
                         binding = JsonUtil.unbox(json);
diff --git a/src/test/java/org/apache/sling/pipes/internal/inputstream/JsonPipeTest.java b/src/test/java/org/apache/sling/pipes/internal/inputstream/JsonPipeTest.java
index 6539fad..169daa8 100644
--- a/src/test/java/org/apache/sling/pipes/internal/inputstream/JsonPipeTest.java
+++ b/src/test/java/org/apache/sling/pipes/internal/inputstream/JsonPipeTest.java
@@ -106,6 +106,11 @@ public class JsonPipeTest extends AbstractPipeTest {
     }
 
     @Test
+    public void testDynamicJsonPath() throws Exception {
+        testJsonPath("{'foo':[{'test':'one'}, {'test':'two'}]}", "$.${(true?'foo':'bar')}");
+    }
+
+    @Test
     public void testSimpleRemoteJson() throws InvocationTargetException, IllegalAccessException {
         http.givenThat(get(urlEqualTo("/get/foo.json"))
                 .willReturn(aResponse().withStatus(200).withBody("{\"args\":{\"foo1\":\"bar\"}}")));