diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/function/Parameter.java b/json-path/src/main/java/com/jayway/jsonpath/internal/function/Parameter.java index b2c85c62..94a3e357 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/function/Parameter.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/function/Parameter.java @@ -129,6 +129,8 @@ public class Parameter { } else { if (value != null && expectedType.isAssignableFrom(value.getClass())) { collection.add(value); + } else if (value != null && expectedType == String.class) { + collection.add(value.toString()); } } } diff --git a/json-path/src/test/java/com/jayway/jsonpath/internal/function/BaseFunctionTest.java b/json-path/src/test/java/com/jayway/jsonpath/internal/function/BaseFunctionTest.java index 8962b38f..b26a2b8f 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/internal/function/BaseFunctionTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/internal/function/BaseFunctionTest.java @@ -14,6 +14,7 @@ import static org.assertj.core.api.Assertions.assertThat; public class BaseFunctionTest { protected static final String NUMBER_SERIES = "{\"empty\": [], \"numbers\" : [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]}"; protected static final String TEXT_SERIES = "{\"urls\": [\"http://api.worldbank.org/countries/all/?format=json\", \"http://api.worldbank.org/countries/all/?format=json\"], \"text\" : [ \"a\", \"b\", \"c\", \"d\", \"e\", \"f\" ]}"; + protected static final String TEXT_AND_NUMBER_SERIES = "{\"text\" : [ \"a\", \"b\", \"c\", \"d\", \"e\", \"f\" ], \"numbers\" : [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]}"; /** * Verify the function returns the correct result based on the input expectedValue @@ -40,6 +41,10 @@ public class BaseFunctionTest { verifyFunction(conf, pathExpr, TEXT_SERIES, expectedValue); } + protected void verifyTextAndNumberFunction(Configuration conf, String pathExpr, Object expectedValue) { + verifyFunction(conf, pathExpr, TEXT_AND_NUMBER_SERIES, expectedValue); + } + protected String getResourceAsText(String resourceName) throws IOException { return new Scanner(BaseFunctionTest.class.getResourceAsStream(resourceName), "UTF-8").useDelimiter("\\A").next(); } diff --git a/json-path/src/test/java/com/jayway/jsonpath/internal/function/NestedFunctionTest.java b/json-path/src/test/java/com/jayway/jsonpath/internal/function/NestedFunctionTest.java index 7ab9f972..2ccc38a7 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/internal/function/NestedFunctionTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/internal/function/NestedFunctionTest.java @@ -69,6 +69,11 @@ public class NestedFunctionTest extends BaseFunctionTest { verifyTextFunction(conf, "$.text.concat()", "abcdef"); } + @Test + public void testStringAndNumberConcat() { + verifyTextAndNumberFunction(conf, "$.concat($.text[0], $.numbers[0])", "a1"); + } + @Test public void testStringConcatWithJSONParameter() { verifyTextFunction(conf, "$.text.concat(\"-\", \"ghijk\")", "abcdef-ghijk");