Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
wnm3 committed Apr 21, 2024
1 parent 7985f7c commit 343c0f1
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 49 deletions.
17 changes: 0 additions & 17 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,6 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="target/generated-sources/annotations">
<attributes>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="m2e-apt" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
Expand All @@ -56,14 +48,5 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The easiest way to use this library is to include it as a dependency in your Mav
<dependency>
<groupId>com.ibm.jsonata4java</groupId>
<artifactId>JSONata4Java</artifactId>
<version>2.4.8</version>
<version>2.4.9</version>
</dependency>
```

Expand Down Expand Up @@ -53,8 +53,8 @@ Note: to build and deploy the jars to Maven Central you need to use a command li
`mvn clean install deploy -Prelease`

Once you have run the launcher, you can find the jar files in the /target directory. There are two&colon;
* **JSONata4Java-2.4.8-jar-with-dependencies.jar** (thinks includes dependent jar files)
* **JSONata4Java-2.4.8.jar** (only the JSONata4Java code)
* **JSONata4Java-2.4.9-jar-with-dependencies.jar** (thinks includes dependent jar files)
* **JSONata4Java-2.4.9.jar** (only the JSONata4Java code)

The com.api.jsonata4java.Tester program enables you to enter an expression and run it
against the same JSON as is used at the https://try.jsonata.org site. You can also
Expand All @@ -72,10 +72,11 @@ methods are not thread-safe.

Issue 260 to add support for timeoutMS and maxDepth to the evaluate methods in Expression.

### New Feature for Version 2.4.8 ###
A new function for $fromMillisZoned has been added to allow passing a Timezone string as the 3rd parameter.
### New Feature for Version 2.4.9 ###
The $number function was updated to allow strings with 0x, 0o, 0b prefixes for hexadecimal, octal, and binary conversions. The value returned can handle long values.

### New Feature for Version 2.4 ###
A new function for $fromMillisZoned has been added to allow passing a Timezone string as the 3rd parameter.
We support now a simple version of JSONata's Order-by operator (see https://docs.jsonata.org/path-operators#---order-by).

### New Features for Version 2 ###
Expand Down
12 changes: 6 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.ibm.jsonata4java</groupId>
<artifactId>JSONata4Java</artifactId>
<version>2.4.8</version>
<version>2.4.9</version>
<name>JSONata4Java</name>
<description>Port of jsonata.js to Java to enable rules for JSON content</description>
<url>https://github.com/IBM/JSONata4Java</url>
Expand Down Expand Up @@ -95,7 +95,7 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.3.24</version>
<version>5.3.34</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -106,24 +106,24 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.16.1</version>
<version>2.17.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.woodstox/woodstox-core -->
<dependency>
<groupId>com.fasterxml.woodstox</groupId>
<artifactId>woodstox-core</artifactId>
<version>6.6.0</version>
<version>6.6.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.16.1</version>
<version>2.17.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-text -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.11.0</version>
<version>1.12.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* (c) Copyright 2018, 2019 IBM Corporation
* 1 New Orchard Road,
* 1 New Orchard Road,
* Armonk, New York, 10504-1722
* United States
* +1 914 499 1900
Expand All @@ -19,10 +19,10 @@
* limitations under the License.
*
*/

package com.api.jsonata4java.expressions.utils;

import java.io.Serializable;

import com.api.jsonata4java.expressions.EvaluateRuntimeException;
import com.fasterxml.jackson.databind.node.DoubleNode;
import com.fasterxml.jackson.databind.node.LongNode;
Expand All @@ -36,20 +36,19 @@ public class NumberUtils implements Serializable {
* The convertNumberToValueNode method converts the string passed in to a
* suitable subclass of ValueNode depending on whether it is an integer or
* decimal.
*
* For consistency with the JavaScript implementation of JSONata, we limit the
* size of the numbers that we handle to be within the range Double.MAX_VALUE
* and -Double.MAX_VALUE. If we did not do this we would need to implement a lot
* of extra code to handle BigInteger and BigDecimal.
*
* @param number
* The string representation of the number to convert
* @return ValueNode The ValueNode representation of the number contained in the
* input string
* @throws EvaluateRuntimeException
* If the number represented by the string is
* outside of the valid range or if the string
* does not contain a valid number.
*
* For consistency with the JavaScript implementation of JSONata, we limit
* the size of the numbers that we handle to be within the range
* Double.MAX_VALUE and -Double.MAX_VALUE. If we did not do this we would
* need to implement a lot of extra code to handle BigInteger and
* BigDecimal.
*
* @param number The string representation of the number to convert
* @return ValueNode The ValueNode representation of the number contained in
* the input string
* @throws EvaluateRuntimeException If the number represented by the string
* is outside of the valid range or if the string does not contain a valid
* number.
*/
public static final ValueNode convertNumberToValueNode(String number) {

Expand All @@ -63,7 +62,7 @@ public static final ValueNode convertNumberToValueNode(String number) {
// Check to see if the converted number is within the acceptable range
if (!doubleValue.isInfinite() && !doubleValue.isNaN()) {
if ((doubleValue >= 0.0d && doubleValue <= Double.valueOf(Long.MAX_VALUE))
|| (doubleValue < 0.0d && doubleValue >= Double.valueOf(Long.MIN_VALUE))) {
|| (doubleValue < 0.0d && doubleValue >= Double.valueOf(Long.MIN_VALUE))) {
if (doubleValue - doubleValue.longValue() == 0.0d) {
result = new LongNode((long) doubleValue.doubleValue());
} else {
Expand All @@ -77,10 +76,45 @@ public static final ValueNode convertNumberToValueNode(String number) {
throw new EvaluateRuntimeException(msg);
}
} catch (NumberFormatException e2) {
// try conversion for other values
result = convertToNumber(number);
}

return result;
}

/**
* Attempts to convert a String based number representation using prefixes
* like 0x (hex), 0o (octal), 0b (binary)
*
* @param number
* @return
*/
public static ValueNode convertToNumber(String number) {
if (number == null) {
final String msg = String.format(Constants.ERR_MSG_UNABLE_TO_CAST_VALUE_TO_NUMBER, number);
throw new EvaluateRuntimeException(msg);
}
number = number.trim().toLowerCase();
ValueNode result = null;
try {
if (number.startsWith("0x")) {
// Hexadecimal number
result = new LongNode(Long.parseLong(number.substring(2), 16));
} else if (number.startsWith("0o")) {
// Octal number
result = new LongNode(Long.parseLong(number.substring(2), 8));
} else if (number.startsWith("0b")) {
// Binary number
result = new LongNode(Long.parseLong(number.substring(2), 2));
} else {
// Decimal number or invalid format
result = new LongNode(Long.parseLong(number));
}
} catch (Exception e) {
final String msg = String.format(Constants.ERR_MSG_UNABLE_TO_CAST_VALUE_TO_NUMBER, number);
throw new EvaluateRuntimeException(msg);
}

return result;
}
}
2 changes: 1 addition & 1 deletion tester.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#! /bin/bash
java -cp target/JSONata4Java-2.4.8-jar-with-dependencies.jar com.api.jsonata4java.Tester $1
java -cp target/JSONata4Java-2.4.9-jar-with-dependencies.jar com.api.jsonata4java.Tester $1
2 changes: 1 addition & 1 deletion testerui.cmd
Original file line number Diff line number Diff line change
@@ -1 +1 @@
java -cp target/JSONata4Java-2.4.8-jar-with-dependencies.jar com.api.jsonata4java.testerui.TesterUI
java -cp target/JSONata4Java-2.4.9-jar-with-dependencies.jar com.api.jsonata4java.testerui.TesterUI
2 changes: 1 addition & 1 deletion testerui.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#! /bin/bash
java -cp target/JSONata4Java-2.4.8-jar-with-dependencies.jar com.api.jsonata4java.testerui.TesterUI
java -cp target/JSONata4Java-2.4.9-jar-with-dependencies.jar com.api.jsonata4java.testerui.TesterUI

0 comments on commit 343c0f1

Please sign in to comment.