Browse Source

Fix concat with text and number (#738)

Co-authored-by: Jost, Michael <michael.jost@sicpa.com>
pull/763/head
mijost 3 years ago committed by GitHub
parent
commit
8e8fc149d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      json-path/src/main/java/com/jayway/jsonpath/internal/function/Parameter.java
  2. 5
      json-path/src/test/java/com/jayway/jsonpath/internal/function/BaseFunctionTest.java
  3. 5
      json-path/src/test/java/com/jayway/jsonpath/internal/function/NestedFunctionTest.java

2
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());
}
}
}

5
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();
}

5
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");

Loading…
Cancel
Save