Skip to content

Commit 022c0e5

Browse files
committed
JSON License is not considered open source
- Remove org.json from project - Fixes jooby-project#2366
1 parent f47eda4 commit 022c0e5

File tree

8 files changed

+57
-61
lines changed

8 files changed

+57
-61
lines changed

modules/jooby-bom/pom.xml

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<!-- THIS FILE IS AUTO GENERATED. DON'T EDIT -->
1717

1818
<properties>
19-
<jooby.version>2.10.0</jooby.version>
19+
<jooby.version>2.10.1-SNAPSHOT</jooby.version>
2020
<HikariCP.version>4.0.3</HikariCP.version>
2121
<archetype-packaging.version>3.2.0</archetype-packaging.version>
2222
<asm.version>9.1</asm.version>
@@ -50,6 +50,7 @@
5050
<jackson.version>2.12.4</jackson.version>
5151
<jacoco-maven-plugin.version>0.8.7</jacoco-maven-plugin.version>
5252
<jacoco.version>0.8.7</jacoco.version>
53+
<jakarta.json.bind-api.version>1.0.2</jakarta.json.bind-api.version>
5354
<jakarta.ws.rs-api.version>2.1.6</jakarta.ws.rs-api.version>
5455
<jasypt.version>1.9.3</jasypt.version>
5556
<javax.inject.version>1</javax.inject.version>
@@ -58,9 +59,8 @@
5859
<jetty.version>9.4.43.v20210629</jetty.version>
5960
<jfiglet.version>0.0.8</jfiglet.version>
6061
<jmespath-java.version>1.11.916</jmespath-java.version>
61-
<jooby-maven-plugin.version>2.10.0</jooby-maven-plugin.version>
62-
<jooby.version>2.10.0</jooby.version>
63-
<json.version>20210307</json.version>
62+
<jooby-maven-plugin.version>2.10.1-SNAPSHOT</jooby-maven-plugin.version>
63+
<jooby.version>2.10.1-SNAPSHOT</jooby.version>
6464
<jsonwebtoken.version>0.11.2</jsonwebtoken.version>
6565
<jsr305.version>3.0.2</jsr305.version>
6666
<junit.version>5.7.1</junit.version>
@@ -472,7 +472,7 @@
472472
<dependency>
473473
<groupId>jakarta.json.bind</groupId>
474474
<artifactId>jakarta.json.bind-api</artifactId>
475-
<version>${json.version}</version>
475+
<version>${jakarta.json.bind-api.version}</version>
476476
<type>jar</type>
477477
</dependency>
478478
<dependency>
@@ -931,12 +931,6 @@
931931
<version>${truth.version}</version>
932932
<type>jar</type>
933933
</dependency>
934-
<dependency>
935-
<groupId>org.json</groupId>
936-
<artifactId>json</artifactId>
937-
<version>${json.version}</version>
938-
<type>jar</type>
939-
</dependency>
940934
<dependency>
941935
<groupId>io.jsonwebtoken</groupId>
942936
<artifactId>jjwt-impl</artifactId>

modules/jooby-cli/pom.xml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,9 @@
4545
<version>3.20.0</version>
4646
</dependency>
4747

48-
<!-- https://mvnrepository.com/artifact/org.json/json -->
4948
<dependency>
50-
<groupId>org.json</groupId>
51-
<artifactId>json</artifactId>
52-
<version>20210307</version>
49+
<groupId>com.google.code.gson</groupId>
50+
<artifactId>gson</artifactId>
5351
</dependency>
5452

5553
<dependency>

modules/jooby-cli/src/main/java/io/jooby/cli/Cli.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
package io.jooby.cli;
77

8+
import com.google.gson.Gson;
9+
import com.google.gson.GsonBuilder;
810
import io.jooby.internal.cli.CommandContextImpl;
911
import io.jooby.internal.cli.JLineCompleter;
1012
import org.jline.reader.EndOfFileException;
@@ -46,6 +48,10 @@
4648
version = "Print version information"
4749
)
4850
public class Cli extends Cmd {
51+
/** JSON parser. */
52+
public static final Gson gson = new GsonBuilder()
53+
.create();
54+
4955
/** Command line specification. */
5056
private @CommandLine.Spec CommandLine.Model.CommandSpec spec;
5157

modules/jooby-cli/src/main/java/io/jooby/cli/Version.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,21 @@
55
*/
66
package io.jooby.cli;
77

8-
import org.json.JSONArray;
9-
import org.json.JSONObject;
10-
import org.json.JSONTokener;
118
import picocli.CommandLine;
129

13-
import java.io.InputStream;
10+
import java.io.InputStreamReader;
11+
import java.io.Reader;
1412
import java.net.URI;
1513
import java.net.URL;
1614
import java.net.URLConnection;
15+
import java.nio.charset.StandardCharsets;
16+
import java.util.List;
17+
import java.util.Map;
1718
import java.util.Objects;
1819
import java.util.Optional;
1920

2021
/**
21-
* Jooby version. It try to fetch latest version from maven repository or fallback to package
22+
* Jooby version. Fetch latest version from maven repository or fallback to package
2223
* implementation version.
2324
*
2425
*/
@@ -37,12 +38,12 @@ private static String doVersion() {
3738
.create("http://search.maven.org/solrsearch/select?q=+g:io.jooby+a:jooby&start=0&rows=1")
3839
.toURL();
3940
URLConnection connection = url.openConnection();
40-
try (InputStream in = connection.getInputStream()) {
41-
JSONObject json = new JSONObject(new JSONTokener(in));
42-
JSONObject response = json.getJSONObject("response");
43-
JSONArray docs = response.getJSONArray("docs");
44-
JSONObject jooby = docs.getJSONObject(0);
45-
return jooby.getString("latestVersion");
41+
try (Reader in = new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8)) {
42+
Map json = Cli.gson.fromJson(in, Map.class);
43+
Map response = (Map) json.get("response");
44+
List docs = (List) response.get("docs");
45+
Map jooby = (Map) docs.get(0);
46+
return (String) jooby.get("latestVersion");
4647
}
4748
} catch (Exception x) {
4849
return Optional.ofNullable(Version.class.getPackage())

modules/jooby-cli/src/main/java/io/jooby/internal/cli/CommandContextImpl.java

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,6 @@
55
*/
66
package io.jooby.internal.cli;
77

8-
import com.github.jknack.handlebars.Handlebars;
9-
import com.github.jknack.handlebars.io.ClassPathTemplateLoader;
10-
import com.github.jknack.handlebars.io.TemplateLoader;
11-
import io.jooby.cli.Context;
12-
import org.jline.reader.LineReader;
13-
import org.json.JSONObject;
14-
import org.json.JSONTokener;
15-
16-
import javax.annotation.Nonnull;
178
import java.io.FileNotFoundException;
189
import java.io.IOException;
1910
import java.io.InputStream;
@@ -32,8 +23,17 @@
3223
import java.util.stream.Collectors;
3324
import java.util.stream.Stream;
3425

35-
public class CommandContextImpl implements Context {
26+
import javax.annotation.Nonnull;
3627

28+
import org.jline.reader.LineReader;
29+
30+
import com.github.jknack.handlebars.Handlebars;
31+
import com.github.jknack.handlebars.io.ClassPathTemplateLoader;
32+
import com.github.jknack.handlebars.io.TemplateLoader;
33+
import io.jooby.cli.Cli;
34+
import io.jooby.cli.Context;
35+
36+
public class CommandContextImpl implements Context {
3737
private final LineReader reader;
3838

3939
private final Handlebars templates;
@@ -42,7 +42,7 @@ public class CommandContextImpl implements Context {
4242

4343
private final String version;
4444

45-
private JSONObject configuration;
45+
private Map configuration;
4646

4747
private Properties versions;
4848

@@ -57,9 +57,9 @@ public CommandContextImpl(LineReader reader, String version) throws IOException
5757
Path file = configurationPath();
5858

5959
if (Files.exists(file)) {
60-
configuration = new JSONObject(new JSONTokener(Files.newBufferedReader(file)));
60+
configuration = Cli.gson.fromJson(Files.newBufferedReader(file), LinkedHashMap.class);
6161
} else {
62-
configuration = new JSONObject();
62+
configuration = new LinkedHashMap();
6363
}
6464
}
6565

@@ -68,21 +68,22 @@ private Path configurationPath() {
6868
}
6969

7070
@Nonnull @Override public String getVersion() {
71-
return configuration.has("version") ? configuration.getString("version") : version;
71+
return (String) configuration.getOrDefault("version", version);
7272
}
7373

7474
@Nonnull @Override public Path getWorkspace() {
75-
return configuration.has("workspace")
76-
? Paths.get(configuration.getString("workspace"))
77-
: Paths.get(System.getProperty("user.dir"));
75+
String workspace = (String) configuration.getOrDefault("workspace",
76+
System.getProperty("user.dir"));
77+
return Paths.get(workspace);
7878
}
7979

8080
@Override public void setWorkspace(@Nonnull Path workspace) throws IOException {
8181
if (!Files.isDirectory(workspace)) {
8282
throw new FileNotFoundException(workspace.toAbsolutePath().toString());
8383
}
8484
configuration.put("workspace", workspace.toAbsolutePath().toString());
85-
Files.write(configurationPath(), configuration.toString().getBytes(StandardCharsets.UTF_8));
85+
String json = Cli.gson.toJson(configuration);
86+
Files.write(configurationPath(), json.getBytes(StandardCharsets.UTF_8));
8687

8788
}
8889

modules/jooby-graphql/pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
</dependency>
2727

2828
<dependency>
29-
<groupId>org.json</groupId>
30-
<artifactId>json</artifactId>
29+
<groupId>com.google.code.gson</groupId>
30+
<artifactId>gson</artifactId>
3131
<optional>true</optional>
3232
</dependency>
3333

@@ -74,13 +74,13 @@
7474
<minimizeJar>true</minimizeJar>
7575
<artifactSet>
7676
<includes>
77-
<include>org.json:*</include>
77+
<include>com.google.code.gson:*</include>
7878
</includes>
7979
</artifactSet>
8080
<relocations>
8181
<relocation>
82-
<pattern>org.json</pattern>
83-
<shadedPattern>${shaded.package}.json</shadedPattern>
82+
<pattern>com.google.gson</pattern>
83+
<shadedPattern>${shaded.package}.gson</shadedPattern>
8484
</relocation>
8585
</relocations>
8686
</configuration>

modules/jooby-graphql/src/main/java/io/jooby/internal/graphql/GraphQLHandler.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,23 @@
55
*/
66
package io.jooby.internal.graphql;
77

8+
import com.google.gson.Gson;
9+
import com.google.gson.GsonBuilder;
810
import graphql.ExecutionInput;
911
import graphql.ExecutionResult;
1012
import graphql.GraphQL;
1113
import io.jooby.Context;
1214
import io.jooby.Route;
1315
import io.jooby.Router;
14-
import org.json.JSONObject;
1516

1617
import javax.annotation.Nonnull;
1718
import java.util.Collections;
1819
import java.util.Map;
1920

2021
public class GraphQLHandler implements Route.Handler {
22+
private static final Gson json = new GsonBuilder()
23+
.create();
24+
2125
protected GraphQL graphQL;
2226

2327
public GraphQLHandler(GraphQL graphQL) {
@@ -39,8 +43,7 @@ protected final ExecutionInput newExecutionInput(@Nonnull Context ctx) {
3943
String operationName = ctx.query("operationName").valueOrNull();
4044
Map<String, Object> variables = ctx.query("variables").toOptional()
4145
.filter(string -> !string.equals("{}"))
42-
.map(JSONObject::new)
43-
.map(JSONObject::toMap)
46+
.map(str -> json.fromJson(str,Map.class))
4447
.orElseGet(Collections::emptyMap);
4548
request.setOperationName(operationName);
4649
request.setQuery(query);

pom.xml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<pebble.version>3.1.5</pebble.version>
2525
<jackson.version>2.12.4</jackson.version>
2626
<gson.version>2.8.6</gson.version>
27+
<jakarta.json.bind-api.version>1.0.2</jakarta.json.bind-api.version>
2728
<yasson.version>1.0.9</yasson.version>
2829
<rocker.version>1.3.0</rocker.version>
2930
<thymeleaf.version>3.0.12.RELEASE</thymeleaf.version>
@@ -92,7 +93,6 @@
9293
<!-- Misc -->
9394
<okhttp.version>4.9.1</okhttp.version>
9495
<jsonwebtoken.version>0.11.2</jsonwebtoken.version>
95-
<json.version>20210307</json.version>
9696
<pac4j.version>4.4.0</pac4j.version>
9797
<quartz.version>2.3.2</quartz.version>
9898
<cron-utils.version>9.1.3</cron-utils.version>
@@ -577,7 +577,7 @@
577577
<dependency>
578578
<groupId>jakarta.json.bind</groupId>
579579
<artifactId>jakarta.json.bind-api</artifactId>
580-
<version>1.0.2</version>
580+
<version>${jakarta.json.bind-api.version}</version>
581581
</dependency>
582582

583583
<dependency>
@@ -1092,13 +1092,6 @@
10921092
<version>${truth.version}</version>
10931093
</dependency>
10941094

1095-
<!-- https://mvnrepository.com/artifact/org.json/json -->
1096-
<dependency>
1097-
<groupId>org.json</groupId>
1098-
<artifactId>json</artifactId>
1099-
<version>${json.version}</version>
1100-
</dependency>
1101-
11021095
<dependency>
11031096
<groupId>io.jsonwebtoken</groupId>
11041097
<artifactId>jjwt-impl</artifactId>

0 commit comments

Comments
 (0)