Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #2094: replace the dependency on yasson with jsonb and jsonp #2130

Merged
merged 6 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions client/implementation-vertx/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@
<artifactId>microprofile-config-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.json.bind</groupId>
<artifactId>jakarta.json.bind-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- The Client API is copied into SmallRye for now -->
<!-- <dependency>-->
<!-- <groupId>org.eclipse.microprofile.graphql</groupId>-->
Expand All @@ -55,5 +65,10 @@
<artifactId>smallrye-graphql-client-model-builder</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse</groupId>
<artifactId>yasson</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
18 changes: 10 additions & 8 deletions client/implementation/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@
<artifactId>jakarta.json-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.json.bind</groupId>
<artifactId>jakarta.json.bind-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.smallrye.config</groupId>
<artifactId>smallrye-config</artifactId>
Expand All @@ -66,14 +71,6 @@
<artifactId>jakarta.enterprise.cdi-api</artifactId>
</dependency>

<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse</groupId>
<artifactId>yasson</artifactId>
</dependency>
<dependency>
<groupId>io.smallrye.reactive</groupId>
<artifactId>mutiny</artifactId>
Expand Down Expand Up @@ -122,5 +119,10 @@
<artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse</groupId>
<artifactId>yasson</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.smallrye.graphql.client.impl;

import java.io.StringReader;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
Expand All @@ -8,18 +9,15 @@
import jakarta.json.JsonBuilderFactory;
import jakarta.json.JsonObject;
import jakarta.json.JsonObjectBuilder;
import jakarta.json.JsonStructure;
import jakarta.json.JsonValue;
import jakarta.json.bind.Jsonb;
import jakarta.json.bind.JsonbBuilder;

import org.eclipse.yasson.internal.JsonBinding;

import io.smallrye.graphql.client.Request;

public class RequestImpl implements Request {

private static final JsonBuilderFactory jsonBuilderFactory = Json.createBuilderFactory(null);
private static final JsonBuilderFactory JSON = Json.createBuilderFactory(null);
private static final Jsonb JSONB = JsonbBuilder.create();

private final String document;
private Map<String, Object> variables;
Expand All @@ -32,7 +30,7 @@ public RequestImpl(String document) {

@Override
public String toJson() {
JsonObjectBuilder queryBuilder = jsonBuilderFactory.createObjectBuilder().add("query", document);
JsonObjectBuilder queryBuilder = JSON.createObjectBuilder().add("query", document);
if (!variables.isEmpty()) {
queryBuilder.add("variables", _formatJsonVariables());
}
Expand All @@ -44,7 +42,7 @@ public String toJson() {

@Override
public JsonObject toJsonObject() {
JsonObjectBuilder queryBuilder = jsonBuilderFactory.createObjectBuilder().add("query", document);
JsonObjectBuilder queryBuilder = JSON.createObjectBuilder().add("query", document);
if (!variables.isEmpty()) {
queryBuilder.add("variables", _formatJsonVariables());
}
Expand All @@ -55,7 +53,7 @@ public JsonObject toJsonObject() {
}

private JsonObject _formatJsonVariables() {
JsonObjectBuilder varBuilder = jsonBuilderFactory.createObjectBuilder();
JsonObjectBuilder varBuilder = JSON.createObjectBuilder();

variables.forEach((k, v) -> {
// Other types to process here
Expand All @@ -74,11 +72,7 @@ private JsonObject _formatJsonVariables() {
} else if (v == null) {
varBuilder.addNull(k);
} else {
try (Jsonb jsonb = JsonbBuilder.create()) {
JsonStructure struct = ((JsonBinding) jsonb).toJsonStructure(v);
varBuilder.add(k, struct);
} catch (Exception ignore) {
}
varBuilder.add(k, Json.createReader(new StringReader(JSONB.toJson(v))).read());
}
});

Expand Down
13 changes: 13 additions & 0 deletions client/tck/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@
<groupId>jakarta.enterprise</groupId>
<artifactId>jakarta.enterprise.cdi-api</artifactId>
</dependency>
<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
</dependency>
<dependency>
<groupId>jakarta.json.bind</groupId>
<artifactId>jakarta.json.bind-api</artifactId>
</dependency>

<dependency>
<groupId>com.graphql-java</groupId>
Expand Down Expand Up @@ -79,5 +87,10 @@
<groupId>io.smallrye</groupId>
<artifactId>smallrye-graphql-client</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse</groupId>
<artifactId>yasson</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
Loading