Skip to content
This repository was archived by the owner on Oct 31, 2024. It is now read-only.

Commit 3514cb1

Browse files
authored
Merge pull request #79 from burtcorp/modernize
Refresh and modernize
2 parents f97047b + 4f8bad7 commit 3514cb1

File tree

23 files changed

+70
-66
lines changed

23 files changed

+70
-66
lines changed

.travis.yml

-9
This file was deleted.

LICENSE.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2016, Burt AB
1+
Copyright (c) 2016, Burt Intelligence AB and contributors
22
All rights reserved.
33

44
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

README.md

+9-13
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,30 @@
11
# jmespath-java
22

3-
[![Build Status](https://travis-ci.org/burtcorp/jmespath-java.png?branch=master)](https://travis-ci.org/burtcorp/jmespath-java)
3+
_If you're reading this on GitHub, please note that this is the readme for the development version and that some features described here might not yet have been released. You can find the readme for a specific version via the release tags ([here is an example](https://github.com/burtcorp/jmespath-java/releases/tag/jmespath-0.5.0))._
44

5-
_If you're reading this on GitHub, please note that this is the readme for the development version and that some features described here might not yet have been released. You can find the readme for a specific version via the release tags ([here is an example](https://github.com/burtcorp/jmespath-java/releases/tag/jmespath-0.1.0))._
6-
7-
This is an implementation of [JMESPath](http://jmespath.org/) for Java and it supports searching JSON documents (via [Jackson](https://github.com/FasterXML/jackson) or [Gson](https://github.com/google/gson)) and structures containing basic Java objects (`Map`, `List`, `String`, etc.) – but can also be extended to work with any JSON-like structure.
5+
This is an implementation of [JMESPath](http://jmespath.org/) for Java. It supports multiple JSON libraries, for example [Jackson](https://github.com/FasterXML/jackson), [Jackson jr](https://github.com/FasterXML/jackson-jr), [Gson](https://github.com/google/gson), and structures containing basic Java objects (`Map`, `List`, `String`, etc.). It can be extended to support any JSON-like structure through a simple adapter.
86

97
## Installation
108

11-
Using Maven you can add this to your dependencies:
9+
You can install the library using Maven:
1210

1311
```xml
1412
<dependency>
1513
<groupId>io.burt</groupId>
16-
<artifactId>jmespath</artifactId>
14+
<artifactId>${jmespath.adapter}</artifactId>
1715
<version>${jmespath.version}</version>
1816
</dependency>
1917
```
2018

21-
Check the [releases page](https://github.com/burtcorp/jmespath-java/releases) for the value of `${jmespath.version}`.
19+
Replace `${jmespath.adapter}` with the adapter you need for your project, for example `jmespath-jackson` or `jmespath-gson`. You can also use `jmespath-core` if you are going to implement your own adapter in your project.
2220

23-
If you don't want both the Jackson and Gson implementations you can change it to `jmespath-jackson` or `jmespath-gson`. Some time before 1.0 the dependencies will probably be reversed so that `jmespath` will not depend on the specific runtimes, so you unless you have the need for multiple runtimes you should depend on the specific runtime you need.
21+
Replace `${jmespath.version}` with the latest version from the [releases page](https://github.com/burtcorp/jmespath-java/releases).
2422

2523
### Dependencies
2624

2725
`jmespath-core` has an ANTLR based parser, but the ANTLR runtime artifact has been shaded into the `io.burt.jmespath` package to avoid conflicts with other artifacts that may depend on ANTLR. This means that `jmespath-core` has no external dependencies.
2826

29-
`jmespath-jackson` obviously depends on Jackson, specifically Jackson DataBind (`com.fasterxml.jackson.core:jackson-databind`), but other than that it only depends on `jmespath-core`.
30-
31-
`jmespath-gson` depends on Gson, specifically `com.google.code.gson:gson`, but other than that only `jmespath-core`.
27+
The adapters each depend on their supporting libraries, for example Jackson Databind for `jmespath-jackson`.
3228

3329
## Basic usage
3430

@@ -59,7 +55,7 @@ JsonNode result = expression.search(input);
5955

6056
## Description
6157

62-
`jmespath-java` comes in three parts: `jmespath-core`, `jmespath-jackson`, and `jmespath-gson`. The former contains the expression parser, core runtime, default functions and a simple runtime adapter that can search structures made up from numbers, strings, booleans, `List` and `Map` available as `io.burt.jmespath.jcf.JcfRuntime` (for "Java Collections Framework"). The latter contains the Jackson and Gson runtime adapters, respectively, and is what you should be using most of the time. The JCF runtime is just for internal development and testing. It primarily exists to test that there's nothing runtime-specific in the implementation.
58+
`jmespath-java` comes in multiple parts: `jmespath-core`, and the adapters for different JSON libraries, like `jmespath-jackson`, and `jmespath-gson`. `jmespath-core` contains the expression parser, core runtime, default functions and a simple runtime adapter that can search structures made up from numbers, strings, booleans, `List` and `Map` available as `io.burt.jmespath.jcf.JcfRuntime` (for "Java Collections Framework"). The latter contains runtime adapters for each specific JSON library, and is what you should be using most of the time. The JCF runtime is just for internal development and testing. It primarily exists to test that there's nothing runtime-specific in the implementation.
6359

6460
## Configuration
6561

@@ -177,4 +173,4 @@ And all dependencies should be installed, the code compiled and the tests run.
177173

178174
# Copyright
179175

180-
© 2016-2018 Burt AB, see LICENSE.txt (BSD 3-Clause).
176+
© 2016 Burt Intelligence AB and contributors, see LICENSE.txt (BSD 3-Clause).

jmespath-core/pom.xml

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
<version>0.5.2-SNAPSHOT</version>
1414
</parent>
1515

16+
<properties>
17+
<antlr.version>4.9.3</antlr.version>
18+
</properties>
19+
1620
<dependencies>
1721
<dependency>
1822
<groupId>org.antlr</groupId>

jmespath-core/src/test/java/io/burt/jmespath/ComplianceRunner.java

+3-7
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,8 @@ private Description createDescription(JmesPathComplianceTest.ComplianceTest<T> c
2929
private Collection<JmesPathComplianceTest.ComplianceTest<T>> getAllTests() {
3030
try {
3131
return testClass.newInstance().getAllTests();
32-
} catch (InstantiationException ie) {
33-
throw new RuntimeException("Could not instantiate runtime", ie);
34-
} catch (IllegalAccessException iae) {
35-
throw new RuntimeException("Could not instantiate runtime", iae);
32+
} catch (InstantiationException | IllegalAccessException e) {
33+
throw new RuntimeException("Could not instantiate runtime", e);
3634
}
3735
}
3836

@@ -42,9 +40,7 @@ public void run(RunNotifier notifier) {
4240
notifier.fireTestStarted(testDescription);
4341
try {
4442
complianceTest.run();
45-
} catch (AssertionError ae) {
46-
notifier.fireTestFailure(new Failure(testDescription, ae));
47-
} catch (Exception e) {
43+
} catch (AssertionError | Exception e) {
4844
notifier.fireTestFailure(new Failure(testDescription, e));
4945
} finally {
5046
notifier.fireTestFinished(testDescription);

jmespath-core/src/test/java/io/burt/jmespath/JmesPathComplianceTest.java

+6-7
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import org.junit.runner.RunWith;
1919
import org.hamcrest.Matcher;
2020

21-
import static org.junit.Assert.assertTrue;
21+
import static org.hamcrest.Matchers.is;
2222
import static org.junit.Assert.assertThat;
2323
import static org.junit.Assert.fail;
2424
import static org.hamcrest.Matchers.containsString;
@@ -72,9 +72,10 @@ public void run() {
7272
Expression<U> compiledExpression = runtime.compile(expression);
7373
U result = compiledExpression.search(input);
7474
if (expectedError == null) {
75-
assertTrue(
75+
assertThat(
7676
String.format("Expected <%s> to be <%s>, expression <%s> compiled expression <%s>", result, expectedResult, expression, compiledExpression),
77-
runtime.compare(expectedResult, result) == 0
77+
runtime.compare(expectedResult, result),
78+
is(0)
7879
);
7980
} else {
8081
fail(String.format("Expected \"%s\" error", expectedError));
@@ -136,10 +137,8 @@ public Iterable<String> getFeatureNames() {
136137
}
137138
}
138139
return featureNames;
139-
} catch (IOException ioe) {
140-
throw new RuntimeException("Could not load compliance feature names", ioe);
141-
} catch (URISyntaxException use) {
142-
throw new RuntimeException("Could not load compliance feature names", use);
140+
} catch (IOException | URISyntaxException e) {
141+
throw new RuntimeException("Could not load compliance feature names", e);
143142
}
144143
}
145144

jmespath-core/src/test/java/io/burt/jmespath/JmesPathRuntimeTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import static org.hamcrest.Matchers.containsString;
3232

3333
public abstract class JmesPathRuntimeTest<T> {
34-
private Adapter<T> runtime = createRuntime(RuntimeConfiguration.defaultConfiguration());
34+
private final Adapter<T> runtime = createRuntime(RuntimeConfiguration.defaultConfiguration());
3535

3636
protected T contact;
3737
protected T cloudtrail;

jmespath-core/src/test/java/io/burt/jmespath/jcf/JcfComplianceTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import io.burt.jmespath.Adapter;
55

66
public class JcfComplianceTest extends JmesPathComplianceTest<Object> {
7-
private Adapter<Object> runtime = new JcfRuntime();
7+
private final Adapter<Object> runtime = new JcfRuntime();
88

99
@Override
1010
protected Adapter<Object> runtime() { return runtime; }

jmespath-core/src/test/java/io/burt/jmespath/jcf/JcfTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ public class JcfTest extends JmesPathRuntimeTest<Object> {
2020
@Test
2121
public void toListReturnsAListWhenGivenAnotherTypeOfCollection() {
2222
List<Object> list = runtime().toList(Collections.singleton(parse("1")));
23-
assertThat(list, is(Arrays.asList(parse("1"))));
23+
assertThat(list, is(Collections.singletonList(parse("1"))));
2424
}
2525
}

jmespath-gson/pom.xml

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
<version>0.5.2-SNAPSHOT</version>
1414
</parent>
1515

16+
<properties>
17+
<gson.version>2.10.1</gson.version>
18+
</properties>
19+
1620
<dependencies>
1721
<dependency>
1822
<groupId>${project.groupId}</groupId>

jmespath-gson/src/main/java/io/burt/jmespath/gson/GsonRuntime.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,13 @@ public boolean isTruthy(JsonElement value) {
9191
case BOOLEAN:
9292
return value.getAsBoolean();
9393
case STRING:
94-
return value.getAsString().length() > 0;
94+
return !value.getAsString().isEmpty();
9595
case NUMBER:
9696
return true;
9797
case ARRAY:
98-
return value.getAsJsonArray().size() > 0;
98+
return !value.getAsJsonArray().isEmpty();
9999
case OBJECT:
100-
return value.getAsJsonObject().size() > 0;
100+
return !value.getAsJsonObject().isEmpty();
101101
}
102102
throw new IllegalStateException(String.format("Unknown node type encountered: %s", value.getClass()));
103103
}

jmespath-gson/src/test/java/io/burt/jmespath/gson/GsonComplianceTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import io.burt.jmespath.JmesPathComplianceTest;
66

77
public class GsonComplianceTest extends JmesPathComplianceTest<JsonElement> {
8-
private Adapter<JsonElement> runtime = new GsonRuntime();
8+
private final Adapter<JsonElement> runtime = new GsonRuntime();
99

1010
@Override
1111
protected Adapter<JsonElement> runtime() {

jmespath-jackson-jr/pom.xml

+6-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
<version>0.5.2-SNAPSHOT</version>
1515
</parent>
1616

17+
<properties>
18+
<jackson-jr.version>2.14.2</jackson-jr.version>
19+
</properties>
20+
1721
<dependencies>
1822
<dependency>
1923
<groupId>${project.groupId}</groupId>
@@ -30,12 +34,12 @@
3034
<dependency>
3135
<groupId>com.fasterxml.jackson.jr</groupId>
3236
<artifactId>jackson-jr-objects</artifactId>
33-
<version>2.14.2</version>
37+
<version>${jackson-jr.version}</version>
3438
</dependency>
3539
<dependency>
3640
<groupId>com.fasterxml.jackson.jr</groupId>
3741
<artifactId>jackson-jr-stree</artifactId>
38-
<version>2.14.2</version>
42+
<version>${jackson-jr.version}</version>
3943
</dependency>
4044
</dependencies>
4145

jmespath-jackson/pom.xml

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
<version>0.5.2-SNAPSHOT</version>
1414
</parent>
1515

16+
<properties>
17+
<jackson.version>2.15.3</jackson.version>
18+
</properties>
19+
1620
<dependencies>
1721
<dependency>
1822
<groupId>${project.groupId}</groupId>

jmespath-jackson/src/main/java/io/burt/jmespath/jackson/JacksonRuntime.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ public boolean isTruthy(JsonNode value) {
9797
case ARRAY:
9898
case BINARY:
9999
case OBJECT:
100-
return value.size() > 0;
100+
return !value.isEmpty();
101101
case STRING:
102-
return value.textValue().length() > 0;
102+
return !value.textValue().isEmpty();
103103
case BOOLEAN:
104104
return value.booleanValue();
105105
case MISSING:

jmespath-jackson/src/test/java/io/burt/jmespath/jackson/JacksonComplianceTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import io.burt.jmespath.Adapter;
77

88
public class JacksonComplianceTest extends JmesPathComplianceTest<JsonNode> {
9-
private Adapter<JsonNode> runtime = new JacksonRuntime();
9+
private final Adapter<JsonNode> runtime = new JacksonRuntime();
1010

1111
@Override
1212
protected Adapter<JsonNode> runtime() { return runtime; }

jmespath-jakarta-jsonp/pom.xml

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
<version>0.5.2-SNAPSHOT</version>
1414
</parent>
1515

16+
<properties>
17+
<jakarta.jsonp.version>1.1.6</jakarta.jsonp.version>
18+
</properties>
19+
1620
<dependencies>
1721
<dependency>
1822
<groupId>${project.groupId}</groupId>

jmespath-jakarta-jsonp/src/main/java/io/burt/jmespath/jakarta/jsonp/JsonpRuntime.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,11 @@ public boolean isTruthy(JsonValue value) {
110110
case TRUE:
111111
return true;
112112
case ARRAY:
113-
return ((JsonArray) value).size() > 0;
113+
return !((JsonArray) value).isEmpty();
114114
case OBJECT:
115-
return ((JsonObject) value).size() > 0;
115+
return !((JsonObject) value).isEmpty();
116116
case STRING:
117-
return ((JsonString) value).getString().length() > 0;
117+
return !((JsonString) value).getString().isEmpty();
118118
default:
119119
throw new IllegalStateException(String.format("Unknown node type encountered: %s", value.getValueType()));
120120
}

jmespath-jakarta-jsonp/src/test/java/io/burt/jmespath/jakarta/jsonp/JsonpComplianceTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import javax.json.JsonValue;
77

88
public class JsonpComplianceTest extends JmesPathComplianceTest<JsonValue> {
9-
private Adapter<JsonValue> runtime = new JsonpRuntime();
9+
private final Adapter<JsonValue> runtime = new JsonpRuntime();
1010

1111
@Override
1212
protected Adapter<JsonValue> runtime() { return runtime; }

jmespath-kotlinx/pom.xml

+7-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
<version>0.5.2-SNAPSHOT</version>
1313
</parent>
1414

15+
<properties>
16+
<kotlin.version>1.6.0</kotlin.version>
17+
<kotlinx.version>1.4.1</kotlinx.version>
18+
</properties>
19+
1520
<dependencies>
1621
<dependency>
1722
<groupId>${project.groupId}</groupId>
@@ -33,9 +38,10 @@
3338
<dependency>
3439
<groupId>org.jetbrains.kotlinx</groupId>
3540
<artifactId>kotlinx-serialization-json</artifactId>
36-
<version>1.4.1</version>
41+
<version>${kotlinx.version}</version>
3742
</dependency>
3843
</dependencies>
44+
3945
<build>
4046
<plugins>
4147
<plugin>
@@ -66,7 +72,4 @@
6672
</plugin>
6773
</plugins>
6874
</build>
69-
<properties>
70-
<kotlin.version>1.6.0</kotlin.version>
71-
</properties>
7275
</project>

jmespath-vertx/pom.xml

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
<version>0.5.2-SNAPSHOT</version>
1414
</parent>
1515

16+
<properties>
17+
<vertx.version>4.4.6</vertx.version>
18+
</properties>
19+
1620
<dependencies>
1721
<dependency>
1822
<groupId>${project.groupId}</groupId>

jmespath-vertx/src/test/java/io/burt/jmespath/vertx/VertxComplianceTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import io.burt.jmespath.Adapter;
55

66
public class VertxComplianceTest extends JmesPathComplianceTest<Object> {
7-
private Adapter<Object> runtime = new VertxRuntime();
7+
private final Adapter<Object> runtime = new VertxRuntime();
88

99
@Override
1010
protected Adapter<Object> runtime() { return runtime; }

pom.xml

+3-8
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,8 @@
1313
<url>https://github.com/burtcorp/jmespath-java</url>
1414

1515
<properties>
16-
<junit.version>4.13.1</junit.version>
16+
<junit.version>4.13.2</junit.version>
1717
<hamcrest.version>1.3</hamcrest.version>
18-
<jackson.version>2.9.9</jackson.version>
19-
<jakarta.jsonp.version>1.1.6</jakarta.jsonp.version>
20-
<gson.version>2.8.5</gson.version>
21-
<antlr.version>4.7.2</antlr.version>
22-
<vertx.version>3.7.1</vertx.version>
2318
<encoding>UTF-8</encoding>
2419
</properties>
2520

@@ -109,8 +104,8 @@
109104
<arg>-Xlint:deprecation</arg>
110105
<arg>-Xlint:unchecked</arg>
111106
</compilerArgs>
112-
<source>7</source>
113-
<target>7</target>
107+
<source>8</source>
108+
<target>8</target>
114109
</configuration>
115110
</plugin>
116111
<plugin>

0 commit comments

Comments
 (0)