findFirst(String input, int fromIndex);
+
+ /**
+ * Finds every non-overlapping match in {@code input}, in order.
+ *
+ *
+ * The default implementation streams through {@link #findFirst} so that
+ * implementations only need to provide that one primitive; override this
+ * method if the underlying engine offers a more efficient bulk-match API.
+ */
+ default List findAll(String input) {
+ List matches = new ArrayList<>();
+ int pos = 0;
+ while (pos <= input.length()) {
+ Optional match = findFirst(input, pos);
+ if (!match.isPresent()) {
+ break;
+ }
+ RegexMatch m = match.get();
+ matches.add(m);
+ pos = m.getIndex() + Math.max(m.getLength(), 1);
+ }
+ return matches;
+ }
+
+ /**
+ * Splits {@code input} around every match of this pattern, following
+ * {@link java.util.regex.Pattern#split(CharSequence)} semantics (no
+ * trailing empty strings).
+ */
+ String[] split(String input);
+}
diff --git a/src/main/java/com/api/jsonata4java/expressions/utils/ArrayUtils.java b/src/main/java/com/api/jsonata4java/expressions/utils/ArrayUtils.java
index eb894377..8fad5839 100644
--- a/src/main/java/com/api/jsonata4java/expressions/utils/ArrayUtils.java
+++ b/src/main/java/com/api/jsonata4java/expressions/utils/ArrayUtils.java
@@ -24,12 +24,12 @@
import java.io.Serializable;
import com.api.jsonata4java.expressions.EvaluateRuntimeException;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.node.ArrayNode;
-import com.fasterxml.jackson.databind.node.JsonNodeFactory;
-import com.fasterxml.jackson.databind.node.JsonNodeType;
-import com.fasterxml.jackson.databind.node.NullNode;
-import com.fasterxml.jackson.databind.node.ValueNode;
+import tools.jackson.databind.JsonNode;
+import tools.jackson.databind.node.ArrayNode;
+import tools.jackson.databind.node.JsonNodeFactory;
+import tools.jackson.databind.node.JsonNodeType;
+import tools.jackson.databind.node.NullNode;
+import tools.jackson.databind.node.ValueNode;
public class ArrayUtils implements Serializable {
@@ -99,8 +99,11 @@ public static boolean compare(JsonNode left, JsonNode right) throws EvaluateRunt
if (left.isTextual() && right.isTextual()) {
result = left.asText().compareTo(right.asText()) > 0;
} else {
- ValueNode a = NumberUtils.convertNumberToValueNode(left.asText());
- ValueNode b = NumberUtils.convertNumberToValueNode(right.asText());
+ // Jackson 3's no-arg asText()/asString() throws for container nodes
+ // (ObjectNode/ArrayNode); Jackson 2 returned "". Pass "" as the default
+ // to preserve the Jackson 2 coercion behavior for non-scalar operands.
+ ValueNode a = NumberUtils.convertNumberToValueNode(left.asText(""));
+ ValueNode b = NumberUtils.convertNumberToValueNode(right.asText(""));
result = Double.valueOf(a.doubleValue()).compareTo(Double.valueOf(b.doubleValue())) > 0;
}
return result;
diff --git a/src/main/java/com/api/jsonata4java/expressions/utils/BooleanUtils.java b/src/main/java/com/api/jsonata4java/expressions/utils/BooleanUtils.java
index c22a7d44..49350551 100644
--- a/src/main/java/com/api/jsonata4java/expressions/utils/BooleanUtils.java
+++ b/src/main/java/com/api/jsonata4java/expressions/utils/BooleanUtils.java
@@ -23,8 +23,8 @@
package com.api.jsonata4java.expressions.utils;
import java.io.Serializable;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
+import tools.jackson.databind.JsonNode;
+import tools.jackson.databind.node.ObjectNode;
public class BooleanUtils implements Serializable {
@@ -86,7 +86,12 @@ public static boolean convertJsonNodeToBoolean(JsonNode node) {
case NULL:
return false;
case BINARY:
- return node.asBoolean();
+ // JSON (and the jsonata.org reference) has no binary type, so
+ // there is no reference semantics to match; Jackson 2 returned
+ // false here, and Jackson 3's no-arg asBoolean() throws for a
+ // BinaryNode. Return false, consistent with the POJO/MISSING/
+ // default cases below and with the prior behavior.
+ return false;
case ARRAY: {
// recurse, returning true as soon as we see an element that casts
// to true
@@ -99,7 +104,7 @@ public static boolean convertJsonNodeToBoolean(JsonNode node) {
return false;
}
case OBJECT:
- return ((ObjectNode) node).elements().hasNext();
+ return ((ObjectNode) node).values().iterator().hasNext();
case MISSING:
return false;
case POJO:
diff --git a/src/main/java/com/api/jsonata4java/expressions/utils/DateTimeUtils.java b/src/main/java/com/api/jsonata4java/expressions/utils/DateTimeUtils.java
index edee159a..0c75ea4b 100644
--- a/src/main/java/com/api/jsonata4java/expressions/utils/DateTimeUtils.java
+++ b/src/main/java/com/api/jsonata4java/expressions/utils/DateTimeUtils.java
@@ -1393,9 +1393,11 @@ public int parse(String value) {
private static int lettersToDecimal(String letters, char aChar) {
int decimal = 0;
+ int place = 1;
char[] chars = letters.toCharArray();
for (int i = 0; i < chars.length; i++) {
- decimal += (chars[chars.length - i - 1] - aChar + 1) * Math.pow(26, i);
+ decimal += (chars[chars.length - i - 1] - aChar + 1) * place;
+ place *= 26;
}
return decimal;
}
diff --git a/src/main/java/com/api/jsonata4java/expressions/utils/FunctionUtils.java b/src/main/java/com/api/jsonata4java/expressions/utils/FunctionUtils.java
index 352aa347..6517aac8 100644
--- a/src/main/java/com/api/jsonata4java/expressions/utils/FunctionUtils.java
+++ b/src/main/java/com/api/jsonata4java/expressions/utils/FunctionUtils.java
@@ -61,11 +61,11 @@
import com.api.jsonata4java.expressions.generated.MappingExpressionParser.StringContext;
import com.api.jsonata4java.expressions.generated.MappingExpressionParser.Unary_opContext;
import com.api.jsonata4java.expressions.generated.MappingExpressionParser.Var_recallContext;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.node.ArrayNode;
-import com.fasterxml.jackson.databind.node.DoubleNode;
-import com.fasterxml.jackson.databind.node.JsonNodeFactory;
-import com.fasterxml.jackson.databind.node.ObjectNode;
+import tools.jackson.databind.JsonNode;
+import tools.jackson.databind.node.ArrayNode;
+import tools.jackson.databind.node.DoubleNode;
+import tools.jackson.databind.node.JsonNodeFactory;
+import tools.jackson.databind.node.ObjectNode;
public class FunctionUtils implements Serializable {
diff --git a/src/main/java/com/api/jsonata4java/expressions/utils/JsonMergeUtils.java b/src/main/java/com/api/jsonata4java/expressions/utils/JsonMergeUtils.java
index c3d8f1e1..da4d2f3b 100644
--- a/src/main/java/com/api/jsonata4java/expressions/utils/JsonMergeUtils.java
+++ b/src/main/java/com/api/jsonata4java/expressions/utils/JsonMergeUtils.java
@@ -25,10 +25,10 @@
import java.io.Serializable;
import java.util.Iterator;
import java.util.Map;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.node.ArrayNode;
-import com.fasterxml.jackson.databind.node.JsonNodeFactory;
-import com.fasterxml.jackson.databind.node.ObjectNode;
+import tools.jackson.databind.JsonNode;
+import tools.jackson.databind.node.ArrayNode;
+import tools.jackson.databind.node.JsonNodeFactory;
+import tools.jackson.databind.node.ObjectNode;
/**
* A utility for merging arbitrary JSON trees. Used during default state
diff --git a/src/main/java/com/api/jsonata4java/expressions/utils/NumberUtils.java b/src/main/java/com/api/jsonata4java/expressions/utils/NumberUtils.java
index fd8b827c..fd70d2d9 100644
--- a/src/main/java/com/api/jsonata4java/expressions/utils/NumberUtils.java
+++ b/src/main/java/com/api/jsonata4java/expressions/utils/NumberUtils.java
@@ -24,9 +24,9 @@
import java.io.Serializable;
import com.api.jsonata4java.expressions.EvaluateRuntimeException;
-import com.fasterxml.jackson.databind.node.DoubleNode;
-import com.fasterxml.jackson.databind.node.LongNode;
-import com.fasterxml.jackson.databind.node.ValueNode;
+import tools.jackson.databind.node.DoubleNode;
+import tools.jackson.databind.node.LongNode;
+import tools.jackson.databind.node.ValueNode;
public class NumberUtils implements Serializable {
diff --git a/src/main/java/com/api/jsonata4java/testerui/TesterUI.java b/src/main/java/com/api/jsonata4java/testerui/TesterUI.java
index e5585621..9295208a 100644
--- a/src/main/java/com/api/jsonata4java/testerui/TesterUI.java
+++ b/src/main/java/com/api/jsonata4java/testerui/TesterUI.java
@@ -55,13 +55,13 @@
import com.api.jsonata4java.expressions.EvaluateRuntimeException;
import com.api.jsonata4java.expressions.Expressions;
import com.api.jsonata4java.expressions.ParseException;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.ObjectWriter;
-import com.fasterxml.jackson.databind.SerializationFeature;
-import com.fasterxml.jackson.dataformat.xml.XmlMapper;
-import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator;
+import tools.jackson.core.JacksonException;
+import tools.jackson.databind.JsonNode;
+import tools.jackson.databind.ObjectMapper;
+import tools.jackson.databind.ObjectWriter;
+import tools.jackson.databind.SerializationFeature;
+import tools.jackson.dataformat.xml.XmlMapper;
+import tools.jackson.dataformat.xml.XmlWriteFeature;
/**
* A Swing UI app to test JSONata4Java interactively similar to the original
@@ -73,7 +73,11 @@ public class TesterUI {
private Expressions expressions;
private final ObjectMapper jsonMapper = new ObjectMapper();
- private final XmlMapper xmlMapper = new XmlMapper();
+ private final XmlMapper xmlMapper = XmlMapper.builder()
+ .enable(SerializationFeature.INDENT_OUTPUT)
+ .enable(XmlWriteFeature.WRITE_XML_DECLARATION)
+ .enable(XmlWriteFeature.WRITE_XML_1_1)
+ .build();
private TesterUISettings settings = new TesterUISettings();
private final JMenuBar menuBar = new JMenuBar();
@@ -105,8 +109,6 @@ public class TesterUI {
protected TesterUI() throws IOException {
- xmlMapper.enable(SerializationFeature.INDENT_OUTPUT);
-
settings.load();
inputArea.setFont(settings.getFont());
@@ -313,7 +315,7 @@ private void inputToJson() {
// nothing to do
break;
}
- } catch (JsonProcessingException e) {
+ } catch (JacksonException e) {
e.printStackTrace();
}
}
@@ -361,7 +363,7 @@ private void formatInput() {
.writeValueAsString(jsonMapper.readTree(inputArea.getText())));
break;
}
- } catch (JsonProcessingException e) {
+ } catch (JacksonException e) {
System.err.println("Input error: " + e.getMessage());
this.outputArea.setText("Input error: " + e.getMessage());
this.inputArea.setBackground(settings.getBackgroundError());
@@ -423,7 +425,7 @@ private void map() {
inNode = jsonMapper.readTree(inputArea.getText());
break;
}
- } catch (JsonProcessingException | RuntimeException e) {
+ } catch (RuntimeException e) {
System.err.println("Input error: " + e.getMessage());
this.outputArea.setText("Input error: " + e.getMessage());
this.inputArea.setBackground(settings.getBackgroundError());
@@ -456,7 +458,7 @@ public void run() {
this.outputArea.setText(e.getMessage());
this.jsonataArea.setBackground(settings.getBackgroundError());
this.outputArea.setBackground(settings.getBackgroundError());
- } catch (JsonProcessingException | RuntimeException e) {
+ } catch (RuntimeException e) {
System.err.println("JSONata mapping error: " + e.getMessage());
this.outputArea.setText("JSONata mapping error: " + e.getMessage());
this.jsonataArea.setBackground(settings.getBackgroundError());
@@ -485,9 +487,6 @@ protected static String readFile(Path filePath) throws IOException {
protected String jsonToXml(final String json) throws IOException {
JsonNode node = jsonMapper.readValue(json, JsonNode.class);
- xmlMapper.configure(SerializationFeature.INDENT_OUTPUT, true);
- xmlMapper.configure(ToXmlGenerator.Feature.WRITE_XML_DECLARATION, true);
- xmlMapper.configure(ToXmlGenerator.Feature.WRITE_XML_1_1, true);
ObjectWriter ow = xmlMapper.writer().withRootName("root");
StringWriter w = new StringWriter();
ow.writeValue(w, node);
diff --git a/src/test/java/com/api/jsonata4java/AgnosticTestSuite.java b/src/test/java/com/api/jsonata4java/AgnosticTestSuite.java
index 08a48f85..7b87b3f2 100644
--- a/src/test/java/com/api/jsonata4java/AgnosticTestSuite.java
+++ b/src/test/java/com/api/jsonata4java/AgnosticTestSuite.java
@@ -85,15 +85,16 @@
import com.api.jsonata4java.expressions.utils.JsonMergeUtils;
import com.api.jsonata4java.expressions.utils.JsonMergeUtilsTest;
import com.api.jsonata4java.expressions.utils.Utils;
-import com.fasterxml.jackson.core.json.JsonWriteFeature;
-import com.fasterxml.jackson.databind.DeserializationFeature;
-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.BooleanNode;
-import com.fasterxml.jackson.databind.node.JsonNodeFactory;
-import com.fasterxml.jackson.databind.node.LongNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
+import tools.jackson.core.json.JsonWriteFeature;
+import tools.jackson.databind.DeserializationFeature;
+import tools.jackson.databind.JsonNode;
+import tools.jackson.databind.ObjectMapper;
+import tools.jackson.databind.json.JsonMapper;
+import tools.jackson.databind.node.ArrayNode;
+import tools.jackson.databind.node.BooleanNode;
+import tools.jackson.databind.node.JsonNodeFactory;
+import tools.jackson.databind.node.LongNode;
+import tools.jackson.databind.node.ObjectNode;
@RunWith(AgnosticTestSuite.class)
// @ExtendWith(AgnosticTestSuiteExtension.class)
@@ -117,14 +118,14 @@ public class AgnosticTestSuite extends ParentRunner {
"function-signatures", // #77
});
- private static final ObjectMapper _objectMapper = new ObjectMapper();
- private static final Map> SKIP_CASES = new HashMap<>();
- static {
+ private static final ObjectMapper _objectMapper = JsonMapper.builder()
// address characters > 127 to be escaped
- _objectMapper.getFactory().configure(JsonWriteFeature.ESCAPE_NON_ASCII.mappedFeature(), true);
+ .enable(JsonWriteFeature.ESCAPE_NON_ASCII)
// ensure we don't have scientific notation for numbers
- _objectMapper.enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS);
-
+ .enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS)
+ .build();
+ private static final Map> SKIP_CASES = new HashMap<>();
+ static {
// due to unparsable use of 'in' in the tests
SKIP_CASES("inclusion-operator", "case004", "case005");
// issue #43 object construction
@@ -278,8 +279,9 @@ private static String readUtf8TextFile(Path path) {
}
private void init() throws Exception {
- final ObjectMapper om = new ObjectMapper();
- om.getFactory().configure(JsonWriteFeature.ESCAPE_NON_ASCII.mappedFeature(), true);
+ final ObjectMapper om = JsonMapper.builder()
+ .enable(JsonWriteFeature.ESCAPE_NON_ASCII)
+ .build();
// load and parse all the dataset json files into memory
System.out.println("Loading datasets");
@@ -600,7 +602,7 @@ protected void runChild(TestGroup group, RunNotifier notifier) {
// introduce bindings if available
String key = "";
ObjectNode bindings = testCase.getBindings();
- for (Iterator it = bindings.fieldNames(); it.hasNext();) {
+ for (Iterator it = bindings.propertyNames().iterator(); it.hasNext();) {
key = it.next();
JsonNode value = bindings.get(key);
e.getEnvironment().setVariable("$" + key, value);
@@ -782,11 +784,14 @@ public TestCase(TestGroup group, String caseName, JsonNode caseJson) {
if (this.expectedResult != null && this.expectedResult.isDouble()) {
double d = this.expectedResult.asDouble();
if (isWholeNumber(d)) {
- this.expectedResult = new LongNode(this.expectedResult.asLong());
+ // Jackson 3's DoubleNode.asLong() throws on out-of-long-range
+ // values; Jackson 2 performed a silent narrowing cast. Replicate
+ // the Jackson 2 behavior so expected-value normalization is unchanged.
+ this.expectedResult = new LongNode((long) d);
} else {
// below produced to high precision and is slower
// BigDecimal bd = new BigDecimal(d);
- // this.expectedResult = new TextNode(bd.toPlainString());
+ // this.expectedResult = new StringNode(bd.toPlainString());
}
}
} else {
@@ -816,7 +821,7 @@ public TestCase(TestGroup group, String caseName, JsonNode caseJson) {
ObjectNode bindings = (ObjectNode) bindTest;
// are there keys to be bound as variables to their content?
String varID = "";
- for (Iterator it = bindings.fieldNames(); it.hasNext();) {
+ for (Iterator it = bindings.propertyNames().iterator(); it.hasNext();) {
varID = it.next();
this.bindings.set(varID, bindings.get(varID));
}
diff --git a/src/test/java/com/api/jsonata4java/JsonataTimeoutTest.java b/src/test/java/com/api/jsonata4java/JsonataTimeoutTest.java
index 7cbe5c91..73488d5d 100644
--- a/src/test/java/com/api/jsonata4java/JsonataTimeoutTest.java
+++ b/src/test/java/com/api/jsonata4java/JsonataTimeoutTest.java
@@ -3,8 +3,8 @@
import org.junit.Test;
import org.junit.Assert;
import com.api.jsonata4java.expressions.Expressions;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
+import tools.jackson.databind.JsonNode;
+import tools.jackson.databind.ObjectMapper;
public class JsonataTimeoutTest {
// issue 245
diff --git a/src/test/java/com/api/jsonata4java/expressions/BasicExpressionsTests.java b/src/test/java/com/api/jsonata4java/expressions/BasicExpressionsTests.java
index 435d7b3a..29a76bf2 100644
--- a/src/test/java/com/api/jsonata4java/expressions/BasicExpressionsTests.java
+++ b/src/test/java/com/api/jsonata4java/expressions/BasicExpressionsTests.java
@@ -43,19 +43,20 @@
import com.api.jsonata4java.expressions.functions.ShuffleFunction;
import com.api.jsonata4java.expressions.functions.SubstringFunction;
import com.api.jsonata4java.expressions.functions.SumFunction;
-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.BooleanNode;
-import com.fasterxml.jackson.databind.node.DoubleNode;
-import com.fasterxml.jackson.databind.node.FloatNode;
-import com.fasterxml.jackson.databind.node.IntNode;
-import com.fasterxml.jackson.databind.node.JsonNodeFactory;
-import com.fasterxml.jackson.databind.node.JsonNodeType;
-import com.fasterxml.jackson.databind.node.LongNode;
-import com.fasterxml.jackson.databind.node.NullNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-import com.fasterxml.jackson.databind.node.TextNode;
+import tools.jackson.core.JacksonException;
+import tools.jackson.databind.JsonNode;
+import tools.jackson.databind.ObjectMapper;
+import tools.jackson.databind.node.ArrayNode;
+import tools.jackson.databind.node.BooleanNode;
+import tools.jackson.databind.node.DoubleNode;
+import tools.jackson.databind.node.FloatNode;
+import tools.jackson.databind.node.IntNode;
+import tools.jackson.databind.node.JsonNodeFactory;
+import tools.jackson.databind.node.JsonNodeType;
+import tools.jackson.databind.node.LongNode;
+import tools.jackson.databind.node.NullNode;
+import tools.jackson.databind.node.ObjectNode;
+import tools.jackson.databind.node.StringNode;
/**
* A collection of poorly-structured test cases. Don't add new tests to this
@@ -217,7 +218,7 @@ public class BasicExpressionsTests implements Serializable {
jsonObj2 = mapper.readTree(json2);
jsonObj3 = mapper.readTree(json3);
jsonObj4 = mapper.readTree(json4);
- } catch (IOException e) {
+ } catch (JacksonException e) {
e.printStackTrace();
}
}
@@ -1316,7 +1317,7 @@ public void testConditionalLazyEval() throws ParseException, EvaluateException,
event.set("t", new FloatNode(-42));
ObjectNode state = mapper.createObjectNode();
- state.set("temperatureStatus", new TextNode("hot"));
+ state.set("temperatureStatus", new StringNode("hot"));
JsonNode result = expression.evaluate(event);
@@ -1338,7 +1339,7 @@ public void testConditionalLazyEval() throws ParseException, EvaluateException,
@Test
public void testNullEquality() throws Exception {
ObjectNode event = mapper.createObjectNode();
- event.put("asdsad", NullNode.getInstance());
+ event.set("asdsad", NullNode.getInstance());
{
Expressions expression = Expressions.parse("asdsad=\"null\"");
Assert.assertEquals(BooleanNode.FALSE, expression.evaluate(event));
@@ -1369,10 +1370,10 @@ public void testNullEquality() throws Exception {
// @Test
// public void test(){
- // Assert.assertTrue( new TextNode("true").asBoolean() );
- // Assert.assertFalse( new TextNode("false").asBoolean() );
- // Assert.assertFalse( new TextNode("T").asBoolean() );
- // Assert.assertFalse( new TextNode("H").asBoolean() );
+ // Assert.assertTrue( new StringNode("true").asBoolean() );
+ // Assert.assertFalse( new StringNode("false").asBoolean() );
+ // Assert.assertFalse( new StringNode("T").asBoolean() );
+ // Assert.assertFalse( new StringNode("H").asBoolean() );
//
// Assert.assertTrue( new IntNode(1).asBoolean() );
// Assert.assertFalse( new IntNode(0).asBoolean() );
@@ -1388,7 +1389,7 @@ public void testNullComparison() throws Exception {
};
ObjectNode event = mapper.createObjectNode();
- event.put("isnull", NullNode.getInstance());
+ event.set("isnull", NullNode.getInstance());
for (String op : ops) {
try {
@@ -1426,7 +1427,7 @@ public void testExistsFunction() throws Exception {
// set to *java* null (not NullNode singleton)
try {
ObjectNode event = mapper.createObjectNode();
- event.put("notset", (ObjectNode) null);
+ event.set("notset", (ObjectNode) null);
Expressions.parse("notset").evaluate(event);
} catch (EvaluateException ex) {
Assert.assertEquals("The property 'notset' does not exist", ex.getMessage());
@@ -1456,10 +1457,10 @@ public void testExistsFunction() throws Exception {
// http://try.jsonata.org/
for (JsonNode valueType : new JsonNode[] {
NullNode.getInstance(), new IntNode(22), BooleanNode.TRUE,
- new LongNode(22L), new TextNode("true"), new IntNode(0), BooleanNode.FALSE, new LongNode(0),
- new TextNode("false"), new TextNode("22")
+ new LongNode(22L), new StringNode("true"), new IntNode(0), BooleanNode.FALSE, new LongNode(0),
+ new StringNode("false"), new StringNode("22")
}) {
- event.put("foo", valueType);
+ event.set("foo", valueType);
Assert.assertEquals(BooleanNode.TRUE, Expressions.parse("$exists(foo)").evaluate(event));
}
}
@@ -2280,4 +2281,134 @@ public void testComplexSelection() throws Exception {
"[{\"a\":[{\"b\":1}]},{\"a\":[{\"b\":2}]}]");
}
+ /**
+ * Ordering operators compare numbers to numbers and strings to strings.
+ * When the two operands have different types (e.g. number vs string) the
+ * reference implementation (jsonata.org) raises "...must be of the same
+ * data type" rather than coercing. Regression guard for issue #432: the
+ * Jackson 3 migration must not let a float operand silently coerce a
+ * string on the other side, and the reported operator must be the one
+ * actually used (the "<" branch previously mis-reported ">").
+ */
+ @Test
+ public void testOrderingAcrossTypes() throws Exception {
+ // valid same-type comparisons still evaluate normally
+ simpleTest("3 < 4.1", "true");
+ simpleTest("3.0 < 4.1", "true");
+ simpleTest("3.14 < 4.15", "true");
+ simpleTest("5.5 < 6", "true");
+ simpleTest("5.5 > 6", "false");
+ simpleTest("5.5 <= 6", "true");
+ simpleTest("5.5 >= 6", "false");
+ simpleTest("\"a\" < \"b\"", "true");
+
+ // number-vs-string is a type mismatch for every ordering operator, and
+ // the message names the operator that was used
+ simpleTestExpectException("3.14 < \"abc\"",
+ "The values 3.14 and \"abc\" either side of operator \"<\" must be of the same data type");
+ simpleTestExpectException("5 < \"3\"",
+ "The values 5 and \"3\" either side of operator \"<\" must be of the same data type");
+ simpleTestExpectException("3.14 > \"abc\"",
+ "The values 3.14 and \"abc\" either side of operator \">\" must be of the same data type");
+ simpleTestExpectException("3.14 <= \"abc\"",
+ "The values 3.14 and \"abc\" either side of operator \"<=\" must be of the same data type");
+ simpleTestExpectException("3.14 >= \"abc\"",
+ "The values 3.14 and \"abc\" either side of operator \">=\" must be of the same data type");
+
+ // A string that happens to parse as a number must NOT be silently
+ // coerced when the other operand is a float. This is the exact
+ // coercion the fix guards against, and it must hold identically for
+ // all four ordering operators, with the string on either side.
+ simpleTestExpectException("\"3\" < 4.1",
+ "The values \"3\" and 4.1 either side of operator \"<\" must be of the same data type");
+ simpleTestExpectException("4.1 < \"3\"",
+ "The values 4.1 and \"3\" either side of operator \"<\" must be of the same data type");
+ simpleTestExpectException("\"3\" > 4.1",
+ "The values \"3\" and 4.1 either side of operator \">\" must be of the same data type");
+ simpleTestExpectException("4.1 > \"3\"",
+ "The values 4.1 and \"3\" either side of operator \">\" must be of the same data type");
+ simpleTestExpectException("\"3\" <= 4.1",
+ "The values \"3\" and 4.1 either side of operator \"<=\" must be of the same data type");
+ simpleTestExpectException("4.1 <= \"3\"",
+ "The values 4.1 and \"3\" either side of operator \"<=\" must be of the same data type");
+ simpleTestExpectException("\"3\" >= 4.1",
+ "The values \"3\" and 4.1 either side of operator \">=\" must be of the same data type");
+ simpleTestExpectException("4.1 >= \"3\"",
+ "The values 4.1 and \"3\" either side of operator \">=\" must be of the same data type");
+ }
+
+ /**
+ * Equality and the "in" operator compare across types by returning
+ * false/true rather than throwing, and never coerce a string to a number.
+ * Regression guard for issue #432.
+ */
+ @Test
+ public void testEqualityAndMembershipAcrossTypes() throws Exception {
+ simpleTest("2 = \"2\"", "false");
+ simpleTest("2 != \"2\"", "true");
+ simpleTest("2 in [1,2,3]", "true");
+ // the string "2" is not a member of an array of numbers
+ simpleTest("\"2\" in [1,2,3]", "false");
+ }
+
+ /**
+ * $join requires a flat array of strings. Any non-string element - a
+ * number, or even a nested array - is an error; the reference
+ * implementation (jsonata.org) does not flatten nested arrays. Regression
+ * guard for issue #434.
+ */
+ @Test
+ public void testJoinRequiresArrayOfStrings() throws Exception {
+ // valid flat array of strings still joins
+ simpleTest("$join([\"a\", \"b\"])", "\"ab\"");
+ simpleTest("$join([\"a\", \"b\", \"c\"])", "\"abc\"");
+
+ final String err = "Argument 1 of function $join must be an array of strings";
+ simpleTestExpectException("$join([1, 2])", err);
+ simpleTestExpectException("$join([[1, 2]])", err);
+ simpleTestExpectException("$join([[\"a\", \"b\"]])", err);
+ }
+
+ /**
+ * Issue #433: out-of-range numeric values must not leak a raw Jackson 3
+ * JsonNodeException from asInt()/asLong(). Bounds, array indexes and numeric
+ * functions now use the widest-safe representation (BigInteger/double) or a
+ * controlled JSONata error, matching jsonata.org 2.2.1 where known.
+ */
+ @Test
+ public void testOutOfRangeNumericCoercion() throws Exception {
+ // Range bounds beyond int/long no longer crash; they raise the controlled
+ // "sequence too big" error (matching jsonata.org's range-size limit).
+ simpleTestExpectException("[1..1e19]",
+ "The size of the sequence allocated by the range operator (..) must not exceed 1e6. Attempted to allocate 10000000000000000000.");
+ simpleTestExpectException("[1..3000000000]",
+ "The size of the sequence allocated by the range operator (..) must not exceed 1e6. Attempted to allocate 3000000000.");
+ // an ordinary small range is unaffected
+ simpleTest("[1..5]", "[1,2,3,4,5]");
+
+ // An array index outside int range is out of bounds -> selects nothing
+ // (undefined), matching jsonata.org, rather than throwing.
+ test("[\"a\", \"b\"][3000000000]", (String) null, null, null);
+
+ // $formatBase uses the full (long) value instead of a 32-bit narrowed int
+ // ($formatBase(5890840712243076) previously overflowed to "1008002948").
+ simpleTest("$formatBase(5890840712243076)", "\"5890840712243076\"");
+ simpleTest("$formatBase(255, 16)", "\"ff\"");
+
+ // $fromMillis with millis beyond long range raises a controlled error
+ // rather than a raw JsonNodeException (reference: Invalid Date).
+ simpleTestExpectException("$fromMillis(1e30)", "Number out of range: \"1.0E30\"");
+
+ // Data-sourced BigInteger operands (which numeric literals never produce,
+ // since large literals become doubles) are handled without crashing.
+ final String bigs = "[99999999999999999999999999, 99999999999999999999999998]";
+ // distinct large integers compare exactly via BigInteger
+ test("$[0] = $[1]", "false", null, bigs);
+ test("$[0] > $[1]", "true", null, bigs);
+ test("$[1] < $[0]", "true", null, bigs);
+ test("$[0] >= $[0]", "true", null, bigs);
+ // unary minus negates a big integer exactly
+ test("-$", "-99999999999999999999999999", null, "99999999999999999999999999");
+ }
+
}
diff --git a/src/test/java/com/api/jsonata4java/expressions/DiacriticsTokenizationTests.java b/src/test/java/com/api/jsonata4java/expressions/DiacriticsTokenizationTests.java
index ea46c4f9..d677debe 100644
--- a/src/test/java/com/api/jsonata4java/expressions/DiacriticsTokenizationTests.java
+++ b/src/test/java/com/api/jsonata4java/expressions/DiacriticsTokenizationTests.java
@@ -31,7 +31,7 @@
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
import com.api.jsonata4java.expressions.utils.Utils;
-import com.fasterxml.jackson.databind.ObjectMapper;
+import tools.jackson.databind.ObjectMapper;
/**
* Allow "any kind of letter from any language" instead of [a-zA-Z] in jsonata expressions
diff --git a/src/test/java/com/api/jsonata4java/expressions/FunctionErrorTest.java b/src/test/java/com/api/jsonata4java/expressions/FunctionErrorTest.java
index 6119bb53..188733d7 100644
--- a/src/test/java/com/api/jsonata4java/expressions/FunctionErrorTest.java
+++ b/src/test/java/com/api/jsonata4java/expressions/FunctionErrorTest.java
@@ -25,7 +25,6 @@
import static com.api.jsonata4java.expressions.utils.Utils.test;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
-import com.api.jsonata4java.expressions.functions.ReplaceFunction;
/**
* A JUnit test class used in order to ease debugging of particular problematic cases.
@@ -179,10 +178,6 @@ public void testRegex_case012() throws Exception {
.replaceAll("\\$\\$", "\\\\\\$")
.replaceAll("([^\\\\]|^)\\$([^0-9^<])", "$1\\\\\\$$2"));
- assertEquals("abc\\$$1xyz", ReplaceFunction.jsonata2JavaReplacement("abc$$$1xyz"));
- assertEquals("abc\\$wxyz", ReplaceFunction.jsonata2JavaReplacement("abc$wxyz"));
- assertEquals("abc\\$$1efg\\$wxyz", ReplaceFunction.jsonata2JavaReplacement("abc$$$1efg$wxyz"));
-
assertEquals("$265", "265USD".replaceAll("([0-9]+)USD", "\\$$1"));
test("$replace(\"265USD\", /([0-9]+)USD/, \"$$$1\")", "\"$265\"", null, null);
}
diff --git a/src/test/java/com/api/jsonata4java/expressions/Jsonata4JavaTestMapper.java b/src/test/java/com/api/jsonata4java/expressions/Jsonata4JavaTestMapper.java
index 765319e3..d6b9029f 100644
--- a/src/test/java/com/api/jsonata4java/expressions/Jsonata4JavaTestMapper.java
+++ b/src/test/java/com/api/jsonata4java/expressions/Jsonata4JavaTestMapper.java
@@ -3,9 +3,9 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
+import tools.jackson.core.JacksonException;
+import tools.jackson.databind.JsonNode;
+import tools.jackson.databind.ObjectMapper;
public class Jsonata4JavaTestMapper {
@@ -37,7 +37,7 @@ public String map(final String in, final boolean beautify) {
} else {
return mapper.writeValueAsString(outputRootNode);
}
- } catch (JsonProcessingException e) {
+ } catch (JacksonException e) {
throw new RuntimeException(e);
}
}
diff --git a/src/test/java/com/api/jsonata4java/expressions/RegularExpressionTest.java b/src/test/java/com/api/jsonata4java/expressions/RegularExpressionTest.java
index 074c02c4..3a3b54b3 100644
--- a/src/test/java/com/api/jsonata4java/expressions/RegularExpressionTest.java
+++ b/src/test/java/com/api/jsonata4java/expressions/RegularExpressionTest.java
@@ -42,15 +42,15 @@ public void testToString() {
@Test
public void find() {
- assertTrue(new RegularExpression("/^.*$/").getPattern().matcher("asdfgh").find());
- assertTrue(new RegularExpression("/^ab.*ef$/").getPattern().matcher("abcdef").find());
- assertTrue(new RegularExpression("/c.*f/").getPattern().matcher("abcdefgh").find());
+ assertTrue(new RegularExpression("/^.*$/").getPattern().test("asdfgh"));
+ assertTrue(new RegularExpression("/^ab.*ef$/").getPattern().test("abcdef"));
+ assertTrue(new RegularExpression("/c.*f/").getPattern().test("abcdefgh"));
}
@Test
public void findCaseInsensitive() {
- assertFalse(new RegularExpression("/^ab.*ef$/").getPattern().matcher("ABCdef").find());
+ assertFalse(new RegularExpression("/^ab.*ef$/").getPattern().test("ABCdef"));
assertTrue(new RegularExpression(RegularExpression.Type.CASEINSENSITIVE, "/^ab.*ef$/")
- .getPattern().matcher("ABCdef").find());
+ .getPattern().test("ABCdef"));
}
}
diff --git a/src/test/java/com/api/jsonata4java/expressions/UnpackFunctionTests.java b/src/test/java/com/api/jsonata4java/expressions/UnpackFunctionTests.java
index 9fe7fc30..dc8e1c38 100644
--- a/src/test/java/com/api/jsonata4java/expressions/UnpackFunctionTests.java
+++ b/src/test/java/com/api/jsonata4java/expressions/UnpackFunctionTests.java
@@ -32,8 +32,8 @@
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
import com.api.jsonata4java.expressions.functions.UnpackFunction;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.node.JsonNodeFactory;
+import tools.jackson.databind.JsonNode;
+import tools.jackson.databind.node.JsonNodeFactory;
/**
* For simplicity, these tests don't rely on $state/$event/$instance access;
diff --git a/src/test/java/com/api/jsonata4java/expressions/path/PathExpressionTests.java b/src/test/java/com/api/jsonata4java/expressions/path/PathExpressionTests.java
index 2d54b9dd..0182d461 100644
--- a/src/test/java/com/api/jsonata4java/expressions/path/PathExpressionTests.java
+++ b/src/test/java/com/api/jsonata4java/expressions/path/PathExpressionTests.java
@@ -32,8 +32,8 @@
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
import com.api.jsonata4java.expressions.EvaluateRuntimeException;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
+import tools.jackson.databind.JsonNode;
+import tools.jackson.databind.ObjectMapper;
@RunWith(Parameterized.class)
public class PathExpressionTests implements Serializable {
diff --git a/src/test/java/com/api/jsonata4java/expressions/regex/RE2RegexPattern.java b/src/test/java/com/api/jsonata4java/expressions/regex/RE2RegexPattern.java
new file mode 100644
index 00000000..e45438e9
--- /dev/null
+++ b/src/test/java/com/api/jsonata4java/expressions/regex/RE2RegexPattern.java
@@ -0,0 +1,106 @@
+/**
+ * (c) Copyright 2018, 2019 IBM Corporation
+ * 1 New Orchard Road,
+ * Armonk, New York, 10504-1722
+ * United States
+ * +1 914 499 1900
+ * support: Nathaniel Mills wnm3@us.ibm.com
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package com.api.jsonata4java.expressions.regex;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+import com.google.re2j.Matcher;
+import com.google.re2j.Pattern;
+
+/**
+ * Demonstration {@link RegexPattern} implementation backed by Google's RE2/J
+ * (https://github.com/google/re2j), a pure-Java, linear-time regex engine
+ * immune to ReDoS (https://en.wikipedia.org/wiki/ReDoS). Shows that
+ * JSONata4Java's regex engine hook (see {@link RegexPattern}/{@link RegexEngine})
+ * is not tied to {@link java.util.regex.Pattern}.
+ *
+ *
+ * Lives under src/test since it's only used to demonstrate/exercise the
+ * hook (see {@link RE2RegexPatternTest}) and isn't part of the library's
+ * runtime dependencies.
+ */
+public final class RE2RegexPattern implements RegexPattern {
+
+ private final Pattern pattern;
+
+ public RE2RegexPattern(String regexPattern, RegexFlags flags) {
+ int re2Flags = 0;
+ if (flags.isCaseInsensitive()) {
+ re2Flags |= Pattern.CASE_INSENSITIVE;
+ }
+ if (flags.isMultiline()) {
+ re2Flags |= Pattern.MULTILINE;
+ }
+ this.pattern = Pattern.compile(regexPattern, re2Flags);
+ }
+
+ /**
+ * Factory for use with {@code Expressions.parse}/{@code Expression.jsonata},
+ * e.g. {@code Expression.jsonata(expr, RE2RegexPattern::new)}.
+ */
+ public static RegexEngine engine() {
+ return RE2RegexPattern::new;
+ }
+
+ @Override
+ public boolean test(String input) {
+ return pattern.matcher(input).find();
+ }
+
+ @Override
+ public Optional findFirst(String input, int fromIndex) {
+ if (fromIndex < 0 || fromIndex > input.length()) {
+ return Optional.empty();
+ }
+ Matcher matcher = pattern.matcher(input);
+ if (!matcher.find(fromIndex)) {
+ return Optional.empty();
+ }
+ return Optional.of(toRegexMatch(matcher));
+ }
+
+ @Override
+ public List findAll(String input) {
+ List matches = new ArrayList<>();
+ Matcher matcher = pattern.matcher(input);
+ while (matcher.find()) {
+ matches.add(toRegexMatch(matcher));
+ }
+ return matches;
+ }
+
+ @Override
+ public String[] split(String input) {
+ return pattern.split(input);
+ }
+
+ private static RegexMatch toRegexMatch(Matcher matcher) {
+ List groups = new ArrayList<>();
+ int groupCount = matcher.groupCount();
+ for (int i = 1; i <= groupCount; i++) {
+ groups.add(matcher.group(i));
+ }
+ return new RegexMatch(matcher.group(), matcher.start(), groups);
+ }
+}
diff --git a/src/test/java/com/api/jsonata4java/expressions/regex/RE2RegexPatternTest.java b/src/test/java/com/api/jsonata4java/expressions/regex/RE2RegexPatternTest.java
new file mode 100644
index 00000000..13390acb
--- /dev/null
+++ b/src/test/java/com/api/jsonata4java/expressions/regex/RE2RegexPatternTest.java
@@ -0,0 +1,105 @@
+/**
+ * (c) Copyright 2018, 2019 IBM Corporation
+ * 1 New Orchard Road,
+ * Armonk, New York, 10504-1722
+ * United States
+ * +1 914 499 1900
+ * support: Nathaniel Mills wnm3@us.ibm.com
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package com.api.jsonata4java.expressions.regex;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import java.io.IOException;
+import com.api.jsonata4java.Expression;
+import com.api.jsonata4java.expressions.EvaluateException;
+import com.api.jsonata4java.expressions.ParseException;
+import tools.jackson.databind.JsonNode;
+import tools.jackson.databind.ObjectMapper;
+import org.junit.Test;
+
+/**
+ * End-to-end tests demonstrating that {@link Expression#jsonata(String, RegexEngine)}
+ * works correctly when plugging in a regex engine other than the default
+ * {@link java.util.regex.Pattern}-backed one -- here, {@link RE2RegexPattern}.
+ */
+public class RE2RegexPatternTest {
+
+ private static JsonNode evaluate(String expression) throws ParseException, IOException, EvaluateException {
+ return Expression.jsonata(expression, RE2RegexPattern.engine()).evaluate(null);
+ }
+
+ @Test
+ public void testMatch() throws Exception {
+ // Note: regex literals containing whitespace hit a pre-existing,
+ // unrelated JSONata4Java grammar limitation (its lexer's global
+ // whitespace-skip rule strips spaces out of regex literals too), so
+ // this intentionally avoids whitespace in the pattern.
+ JsonNode result = evaluate("$match(\"hello-world\", /o-w/)");
+ assertEquals("o-w", result.get("match").asText());
+ assertEquals(4, result.get("index").asInt());
+ }
+
+ @Test
+ public void testMatchCaseInsensitive() throws Exception {
+ JsonNode result = evaluate("$match(\"HELLO\", /hello/i)");
+ assertEquals("HELLO", result.get("match").asText());
+ }
+
+ @Test
+ public void testContains() throws Exception {
+ assertTrue(evaluate("$contains(\"hello\", /ell/)").asBoolean());
+ assertFalse(evaluate("$contains(\"hello\", /xyz/)").asBoolean());
+ }
+
+ @Test
+ public void testReplaceWithGroupReference() throws Exception {
+ JsonNode result = evaluate("$replace(\"John Smith\", /(\\w+)\\s(\\w+)/, \"$2, $1\")");
+ assertEquals("Smith, John", result.asText());
+ }
+
+ @Test
+ public void testSplit() throws Exception {
+ JsonNode result = evaluate("$split(\"a1b2c3\", /[0-9]/)");
+ ObjectMapper mapper = new ObjectMapper();
+ assertEquals(mapper.readTree("[\"a\",\"b\",\"c\"]"), result);
+ }
+
+ @Test
+ public void testRejectsBackreferences() {
+ // RE2 (and therefore RE2/J) deliberately does not support
+ // backreferences, since they make linear-time matching impossible --
+ // this is exactly the ReDoS-prone construct a custom RegexEngine is
+ // meant to let callers reject at the source.
+ try {
+ evaluate("$contains(\"aa\", /(a)\\1/)");
+ org.junit.Assert.fail("Expected an exception compiling a backreference with RE2/J");
+ } catch (Exception expected) {
+ // expected: RE2/J's Pattern.compile rejects the unsupported syntax
+ }
+ }
+
+ @Test
+ public void testEvalUsesEnclosingRegexEngine() throws Exception {
+ // $eval()'d expressions must inherit the enclosing expression's
+ // regex engine rather than silently falling back to the default
+ // java.util.regex-backed one.
+ JsonNode result = evaluate("$eval(\"$match('hello-world', /o-w/).match\")");
+ assertEquals("o-w", result.asText());
+ }
+}
diff --git a/src/test/java/com/api/jsonata4java/expressions/utils/JsonMergeUtilsTest.java b/src/test/java/com/api/jsonata4java/expressions/utils/JsonMergeUtilsTest.java
index e3fe623d..d91786f3 100644
--- a/src/test/java/com/api/jsonata4java/expressions/utils/JsonMergeUtilsTest.java
+++ b/src/test/java/com/api/jsonata4java/expressions/utils/JsonMergeUtilsTest.java
@@ -33,8 +33,8 @@
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
+import tools.jackson.databind.JsonNode;
+import tools.jackson.databind.ObjectMapper;
/**
* Runs the test cases defined in src/test/resources/JsonMergeUtilsTest.json
@@ -81,7 +81,7 @@ public void testCase() throws Exception {
}
- // public static JsonNode merge(String x, String y) throws JsonProcessingException, IOException {
+ // public static JsonNode merge(String x, String y) throws JacksonException, IOException {
// return merge(, OM.readTree(y));
// }
//
diff --git a/src/test/java/com/api/jsonata4java/expressions/utils/Utils.java b/src/test/java/com/api/jsonata4java/expressions/utils/Utils.java
index 446a56db..394e2cd9 100644
--- a/src/test/java/com/api/jsonata4java/expressions/utils/Utils.java
+++ b/src/test/java/com/api/jsonata4java/expressions/utils/Utils.java
@@ -35,13 +35,15 @@
import com.api.jsonata4java.expressions.EvaluateException;
import com.api.jsonata4java.expressions.Expressions;
import com.api.jsonata4java.expressions.ParseException;
-import com.fasterxml.jackson.core.JsonProcessingException;
-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.JsonNodeFactory;
-import com.fasterxml.jackson.databind.node.LongNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
+import tools.jackson.core.JacksonException;
+import tools.jackson.databind.DeserializationFeature;
+import tools.jackson.databind.JsonNode;
+import tools.jackson.databind.ObjectMapper;
+import tools.jackson.databind.json.JsonMapper;
+import tools.jackson.databind.node.ArrayNode;
+import tools.jackson.databind.node.JsonNodeFactory;
+import tools.jackson.databind.node.LongNode;
+import tools.jackson.databind.node.ObjectNode;
public class Utils implements Serializable {
@@ -70,12 +72,17 @@ public static String generateOrgId() {
return new String(buf);
}
- public static JsonNode getJson(String filePath) throws JsonProcessingException, IOException {
+ public static JsonNode getJson(String filePath) throws JacksonException, IOException {
ObjectMapper m = new ObjectMapper();
return m.readTree(new File(filePath));
}
- public static final ObjectMapper mapper = new ObjectMapper();
+ // Jackson 3 flipped FAIL_ON_TRAILING_TOKENS to true by default; Jackson 2
+ // silently ignored content after the first parsed value. Restore the
+ // Jackson 2 default so existing test inputs parse identically.
+ public static final ObjectMapper mapper = JsonMapper.builder()
+ .disable(DeserializationFeature.FAIL_ON_TRAILING_TOKENS)
+ .build();
public static void simpleTest(String expression, String expected) throws Exception {
test(expression, expected, null, null);
diff --git a/src/test/java/com/api/jsonata4java/test/expressions/BasicExpressionsTests.java b/src/test/java/com/api/jsonata4java/test/expressions/BasicExpressionsTests.java
index f69e81d9..148a5fe4 100644
--- a/src/test/java/com/api/jsonata4java/test/expressions/BasicExpressionsTests.java
+++ b/src/test/java/com/api/jsonata4java/test/expressions/BasicExpressionsTests.java
@@ -48,19 +48,20 @@
import com.api.jsonata4java.expressions.functions.ShuffleFunction;
import com.api.jsonata4java.expressions.functions.SubstringFunction;
import com.api.jsonata4java.expressions.functions.SumFunction;
-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.BooleanNode;
-import com.fasterxml.jackson.databind.node.DoubleNode;
-import com.fasterxml.jackson.databind.node.FloatNode;
-import com.fasterxml.jackson.databind.node.IntNode;
-import com.fasterxml.jackson.databind.node.JsonNodeFactory;
-import com.fasterxml.jackson.databind.node.JsonNodeType;
-import com.fasterxml.jackson.databind.node.LongNode;
-import com.fasterxml.jackson.databind.node.NullNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-import com.fasterxml.jackson.databind.node.TextNode;
+import tools.jackson.core.JacksonException;
+import tools.jackson.databind.JsonNode;
+import tools.jackson.databind.ObjectMapper;
+import tools.jackson.databind.node.ArrayNode;
+import tools.jackson.databind.node.BooleanNode;
+import tools.jackson.databind.node.DoubleNode;
+import tools.jackson.databind.node.FloatNode;
+import tools.jackson.databind.node.IntNode;
+import tools.jackson.databind.node.JsonNodeFactory;
+import tools.jackson.databind.node.JsonNodeType;
+import tools.jackson.databind.node.LongNode;
+import tools.jackson.databind.node.NullNode;
+import tools.jackson.databind.node.ObjectNode;
+import tools.jackson.databind.node.StringNode;
/**
* A collection of poorly-structured test cases. Don't add new tests to this
@@ -214,7 +215,7 @@ public class BasicExpressionsTests implements Serializable {
jsonObj = mapper.readTree(json);
jsonObj2 = mapper.readTree(json2);
jsonObj3 = mapper.readTree(json3);
- } catch (IOException e) {
+ } catch (JacksonException e) {
e.printStackTrace();
}
}
@@ -1351,7 +1352,7 @@ public void testConditionalLazyEval() throws ParseException, EvaluateException,
event.set("t", new FloatNode(-42));
ObjectNode state = mapper.createObjectNode();
- state.set("temperatureStatus", new TextNode("hot"));
+ state.set("temperatureStatus", new StringNode("hot"));
JsonNode result = expression.evaluate(event);
@@ -1373,7 +1374,7 @@ public void testConditionalLazyEval() throws ParseException, EvaluateException,
@Test
public void testNullEquality() throws Exception {
ObjectNode event = mapper.createObjectNode();
- event.put("asdsad", NullNode.getInstance());
+ event.set("asdsad", NullNode.getInstance());
{
Expressions expression = Expressions.parse("asdsad=\"null\"");
Assert.assertEquals(BooleanNode.FALSE, expression.evaluate(event));
@@ -1404,10 +1405,10 @@ public void testNullEquality() throws Exception {
// @Test
// public void test(){
- // Assert.assertTrue( new TextNode("true").asBoolean() );
- // Assert.assertFalse( new TextNode("false").asBoolean() );
- // Assert.assertFalse( new TextNode("T").asBoolean() );
- // Assert.assertFalse( new TextNode("H").asBoolean() );
+ // Assert.assertTrue( new StringNode("true").asBoolean() );
+ // Assert.assertFalse( new StringNode("false").asBoolean() );
+ // Assert.assertFalse( new StringNode("T").asBoolean() );
+ // Assert.assertFalse( new StringNode("H").asBoolean() );
//
// Assert.assertTrue( new IntNode(1).asBoolean() );
// Assert.assertFalse( new IntNode(0).asBoolean() );
@@ -1423,7 +1424,7 @@ public void testNullComparison() throws Exception {
};
ObjectNode event = mapper.createObjectNode();
- event.put("isnull", NullNode.getInstance());
+ event.set("isnull", NullNode.getInstance());
for (String op : ops) {
try {
@@ -1461,7 +1462,7 @@ public void testExistsFunction() throws Exception {
// set to *java* null (not NullNode singleton)
try {
ObjectNode event = mapper.createObjectNode();
- event.put("notset", (ObjectNode) null);
+ event.set("notset", (ObjectNode) null);
Expressions.parse("notset").evaluate(event);
} catch (EvaluateException ex) {
Assert.assertEquals("The property 'notset' does not exist", ex.getMessage());
@@ -1491,10 +1492,10 @@ public void testExistsFunction() throws Exception {
// http://try.jsonata.org/
for (JsonNode valueType : new JsonNode[] {
NullNode.getInstance(), new IntNode(22), BooleanNode.TRUE,
- new LongNode(22L), new TextNode("true"), new IntNode(0), BooleanNode.FALSE, new LongNode(0),
- new TextNode("false"), new TextNode("22")
+ new LongNode(22L), new StringNode("true"), new IntNode(0), BooleanNode.FALSE, new LongNode(0),
+ new StringNode("false"), new StringNode("22")
}) {
- event.put("foo", valueType);
+ event.set("foo", valueType);
Assert.assertEquals(BooleanNode.TRUE, Expressions.parse("$exists(foo)").evaluate(event));
}
}
diff --git a/src/test/java/com/api/jsonata4java/testerui/TesterUITest.java b/src/test/java/com/api/jsonata4java/testerui/TesterUITest.java
index ac720021..082b1fb9 100644
--- a/src/test/java/com/api/jsonata4java/testerui/TesterUITest.java
+++ b/src/test/java/com/api/jsonata4java/testerui/TesterUITest.java
@@ -6,9 +6,10 @@
import java.nio.file.Paths;
import org.junit.Before;
import org.junit.Test;
-import com.fasterxml.jackson.core.JsonFactory;
-import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.core.JsonParser;
+import tools.jackson.core.JacksonException;
+import tools.jackson.core.json.JsonFactory;
+import tools.jackson.core.JsonGenerator;
+import tools.jackson.core.JsonParser;
public class TesterUITest {
@@ -40,7 +41,7 @@ public static String minifyJson(final String in) {
while (parser.nextToken() != null) {
gen.copyCurrentEvent(parser);
}
- } catch (IOException e) {
+ } catch (JacksonException e) {
throw new RuntimeException(e);
}
return sw.getBuffer().toString();
diff --git a/src/test/java/testmanually/ExpressionTestPerformance.java b/src/test/java/testmanually/ExpressionTestPerformance.java
index be698a7b..b2acdb19 100644
--- a/src/test/java/testmanually/ExpressionTestPerformance.java
+++ b/src/test/java/testmanually/ExpressionTestPerformance.java
@@ -24,10 +24,10 @@
import org.junit.Test;
import com.api.jsonata4java.expressions.Jsonata4JavaTestMapper;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.JsonMappingException;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
+import tools.jackson.core.JacksonException;
+import tools.jackson.databind.DatabindException;
+import tools.jackson.databind.JsonNode;
+import tools.jackson.databind.ObjectMapper;
/**
* Performance test for big expressions.
@@ -95,7 +95,7 @@ public void testWithBigInput_withParentPath() throws Exception {
System.out.println("END: mapping, took " + (System.currentTimeMillis() - startMillis) + " ms");
}
- private JsonNode generateBigJson() throws JsonProcessingException, JsonMappingException {
+ private JsonNode generateBigJson() throws JacksonException, DatabindException {
StringBuilder sb = new StringBuilder();
sb.append("{\"list\":[");
for (int i = 0; i < 2500000; i++) {
diff --git a/src/test/java/testmanually/JsonataUnitTests.java b/src/test/java/testmanually/JsonataUnitTests.java
index 45cb2053..0473fefe 100644
--- a/src/test/java/testmanually/JsonataUnitTests.java
+++ b/src/test/java/testmanually/JsonataUnitTests.java
@@ -31,7 +31,7 @@
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
-import com.fasterxml.jackson.databind.ObjectMapper;
+import tools.jackson.databind.ObjectMapper;
/**
* Verify behavior when access special $state, $event and $instance variables.
diff --git a/src/test/java/testmanually/TestBindingReference.java b/src/test/java/testmanually/TestBindingReference.java
index 36c4bbec..0857a25a 100644
--- a/src/test/java/testmanually/TestBindingReference.java
+++ b/src/test/java/testmanually/TestBindingReference.java
@@ -7,10 +7,10 @@
import org.junit.Test;
import com.api.jsonata4java.Binding;
import com.api.jsonata4java.Expression;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.node.IntNode;
-import com.fasterxml.jackson.databind.node.TextNode;
+import tools.jackson.databind.JsonNode;
+import tools.jackson.databind.ObjectMapper;
+import tools.jackson.databind.node.IntNode;
+import tools.jackson.databind.node.StringNode;
public class TestBindingReference implements Serializable {
@@ -68,7 +68,7 @@ public void supportsContextualizedConstruction() throws Exception {
bindingList.add(bindingNode);
JsonNode actual = jsonataExpr.evaluate(rootContextNode, bindingList);
- JsonNode expected = new TextNode("bar");
+ JsonNode expected = new StringNode("bar");
Assert.assertEquals(expected, actual);
json = "{\"bar\": [ 4, 5, 6]}";
diff --git a/src/test/java/testmanually/ThreadTester.java b/src/test/java/testmanually/ThreadTester.java
index 7d2bb07d..74fa3881 100644
--- a/src/test/java/testmanually/ThreadTester.java
+++ b/src/test/java/testmanually/ThreadTester.java
@@ -4,8 +4,8 @@
import org.springframework.core.task.SimpleAsyncTaskExecutor;
import org.springframework.core.task.TaskExecutor;
import com.api.jsonata4java.expressions.Expressions;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
+import tools.jackson.databind.JsonNode;
+import tools.jackson.databind.ObjectMapper;
public class ThreadTester {
diff --git a/tester.sh b/tester.sh
index bc90c17c..bc4ef998 100755
--- a/tester.sh
+++ b/tester.sh
@@ -1,2 +1,2 @@
#! /bin/bash
-java -cp target/JSONata4Java-2.6.3-jar-with-dependencies.jar com.api.jsonata4java.Tester $1
+java -cp target/JSONata4Java-3.0.0-jar-with-dependencies.jar com.api.jsonata4java.Tester $1
diff --git a/testerui.cmd b/testerui.cmd
index 3ba09486..a46ec9ad 100644
--- a/testerui.cmd
+++ b/testerui.cmd
@@ -1 +1 @@
-java -cp target/JSONata4Java-2.6.3-jar-with-dependencies.jar com.api.jsonata4java.testerui.TesterUI
+java -cp target/JSONata4Java-3.0.0-jar-with-dependencies.jar com.api.jsonata4java.testerui.TesterUI
diff --git a/testerui.sh b/testerui.sh
index fc010916..e88b778d 100755
--- a/testerui.sh
+++ b/testerui.sh
@@ -1,2 +1,2 @@
#! /bin/bash
-java -cp target/JSONata4Java-2.6.3-jar-with-dependencies.jar com.api.jsonata4java.testerui.TesterUI
+java -cp target/JSONata4Java-3.0.0-jar-with-dependencies.jar com.api.jsonata4java.testerui.TesterUI