From 56e1715bb9d40ed751c4e377a3d1ee47aab84380 Mon Sep 17 00:00:00 2001 From: jonmv Date: Fri, 21 Oct 2022 13:25:37 +0200 Subject: Replace gson with jackson in client module --- client/pom.xml | 5 ++--- client/src/main/java/ai/vespa/client/dsl/Annotation.java | 2 +- client/src/main/java/ai/vespa/client/dsl/DotProduct.java | 2 +- client/src/main/java/ai/vespa/client/dsl/Q.java | 13 +++++++++++-- client/src/main/java/ai/vespa/client/dsl/Wand.java | 3 ++- client/src/main/java/ai/vespa/client/dsl/WeightedSet.java | 2 +- 6 files changed, 18 insertions(+), 9 deletions(-) diff --git a/client/pom.xml b/client/pom.xml index 1da3cbc68c5..9d643d63cf8 100644 --- a/client/pom.xml +++ b/client/pom.xml @@ -18,9 +18,8 @@ - com.google.code.gson - gson - ${gson.version} + com.fasterxml.jackson.core + jackson-databind org.apache.commons diff --git a/client/src/main/java/ai/vespa/client/dsl/Annotation.java b/client/src/main/java/ai/vespa/client/dsl/Annotation.java index ae95ed8647c..66887365d73 100644 --- a/client/src/main/java/ai/vespa/client/dsl/Annotation.java +++ b/client/src/main/java/ai/vespa/client/dsl/Annotation.java @@ -31,7 +31,7 @@ public class Annotation { @Override public String toString() { - return annotations == null || annotations.isEmpty() ? "" : Q.gson.toJson(annotations); + return annotations == null || annotations.isEmpty() ? "" : Q.toJson(annotations); } } diff --git a/client/src/main/java/ai/vespa/client/dsl/DotProduct.java b/client/src/main/java/ai/vespa/client/dsl/DotProduct.java index 0132c4cd4da..4e696a0b825 100644 --- a/client/src/main/java/ai/vespa/client/dsl/DotProduct.java +++ b/client/src/main/java/ai/vespa/client/dsl/DotProduct.java @@ -21,7 +21,7 @@ public class DotProduct extends QueryChain { @Override public String toString() { - return "dotProduct(" + fieldName + ", " + Q.gson.toJson(weightedSet) + ")"; + return "dotProduct(" + fieldName + ", " + Q.toJson(weightedSet) + ")"; } @Override diff --git a/client/src/main/java/ai/vespa/client/dsl/Q.java b/client/src/main/java/ai/vespa/client/dsl/Q.java index cfc0121c3f3..70e0e644c07 100644 --- a/client/src/main/java/ai/vespa/client/dsl/Q.java +++ b/client/src/main/java/ai/vespa/client/dsl/Q.java @@ -1,7 +1,8 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package ai.vespa.client.dsl; -import com.google.gson.Gson; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import java.util.List; import java.util.Map; @@ -12,7 +13,15 @@ import java.util.Map; */ public final class Q { - static Gson gson = new Gson(); + private static final ObjectMapper mapper = new ObjectMapper(); + static String toJson(Object o) { + try { + return mapper.writeValueAsString(o); + } + catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + } private static Sources SELECT_ALL_FROM_SOURCES_ALL = new Sources(new Select("*"), "*"); public static Select select(String fieldName) { return new Select(fieldName); diff --git a/client/src/main/java/ai/vespa/client/dsl/Wand.java b/client/src/main/java/ai/vespa/client/dsl/Wand.java index bda5e2d9802..56bf3e3cf1d 100644 --- a/client/src/main/java/ai/vespa/client/dsl/Wand.java +++ b/client/src/main/java/ai/vespa/client/dsl/Wand.java @@ -65,7 +65,8 @@ public class Wand extends QueryChain { @Override public String toString() { boolean hasAnnotation = A.hasAnnotation(annotation); - String s = Text.format("wand(%s, %s)", fieldName, Q.gson.toJson(value)); + String s = Text.format("wand(%s, %s)", fieldName, Q.toJson(value)); return hasAnnotation ? Text.format("([%s]%s)", annotation, s) : s; } + } diff --git a/client/src/main/java/ai/vespa/client/dsl/WeightedSet.java b/client/src/main/java/ai/vespa/client/dsl/WeightedSet.java index e4162003451..c497abd4965 100644 --- a/client/src/main/java/ai/vespa/client/dsl/WeightedSet.java +++ b/client/src/main/java/ai/vespa/client/dsl/WeightedSet.java @@ -21,7 +21,7 @@ public class WeightedSet extends QueryChain { @Override public String toString() { - return "weightedSet(" + fieldName + ", " + Q.gson.toJson(weightedSet) + ")"; + return "weightedSet(" + fieldName + ", " + Q.toJson(weightedSet) + ")"; } @Override -- cgit v1.2.3