summaryrefslogtreecommitdiffstats
path: root/document
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2023-11-23 16:07:43 +0100
committerHenning Baldersheim <balder@yahoo-inc.com>2023-11-23 16:12:51 +0100
commitef535f6c51393d945d9fe07de38de224d5ae443f (patch)
tree2f5976537a200aebbf6644b8e1ef93f2c669319d /document
parentf966346429c85fc31c8ea962b518e02a19f77f46 (diff)
jackson 2.16 changes some of its default settings so we consolidate our use of the ObjectMapper.
Unless special options are used, use a common instance, or create via factory metod.
Diffstat (limited to 'document')
-rw-r--r--document/src/test/java/com/yahoo/document/DocumentTestCase.java6
-rw-r--r--document/src/test/java/com/yahoo/document/json/JsonWriterTestCase.java11
2 files changed, 8 insertions, 9 deletions
diff --git a/document/src/test/java/com/yahoo/document/DocumentTestCase.java b/document/src/test/java/com/yahoo/document/DocumentTestCase.java
index 679c9284a20..09feed57d92 100644
--- a/document/src/test/java/com/yahoo/document/DocumentTestCase.java
+++ b/document/src/test/java/com/yahoo/document/DocumentTestCase.java
@@ -1,8 +1,8 @@
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.document;
+import ai.vespa.json.Jackson;
import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.ObjectMapper;
import com.yahoo.document.datatypes.Array;
import com.yahoo.document.datatypes.BoolFieldValue;
import com.yahoo.document.datatypes.ByteFieldValue;
@@ -29,10 +29,8 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
-import java.util.Arrays;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -960,7 +958,7 @@ public class DocumentTestCase extends DocumentTestCaseBase {
setUpSertestDocType();
Document doc = getSertestDocument();
String json = doc.toJson();
- Map<String, Object> parsed = new ObjectMapper().readValue(json, new TypeReference<>() {
+ Map<String, Object> parsed = Jackson.mapper().readValue(json, new TypeReference<>() {
});
assertEquals(parsed.get("id"), "id:ns:sertest::foobar");
assertTrue(parsed.get("fields") instanceof Map);
diff --git a/document/src/test/java/com/yahoo/document/json/JsonWriterTestCase.java b/document/src/test/java/com/yahoo/document/json/JsonWriterTestCase.java
index 0e8f3bbaf47..c713048f2ef 100644
--- a/document/src/test/java/com/yahoo/document/json/JsonWriterTestCase.java
+++ b/document/src/test/java/com/yahoo/document/json/JsonWriterTestCase.java
@@ -1,6 +1,7 @@
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.document.json;
+import ai.vespa.json.Jackson;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.io.JsonStringEncoder;
@@ -241,7 +242,7 @@ public class JsonWriterTestCase {
String docId = "id:unittest:testmap::whee";
Document doc = readDocumentFromJson(docId, fields);
- ObjectMapper m = new ObjectMapper();
+ var m = Jackson.mapper();
Map<?, ?> generated = m.readValue(JsonWriter.toByteArray(doc), Map.class);
assertEquals(docId, generated.get("id"));
// and from here on down there will be lots of unchecked casting and
@@ -262,7 +263,7 @@ public class JsonWriterTestCase {
// we have to do everything by hand to check, as maps are unordered, but
// are serialized as an ordered structure
- ObjectMapper m = new ObjectMapper();
+ var m = Jackson.mapper();
Map<?, ?> generated = m.readValue(JsonWriter.toByteArray(doc), Map.class);
assertEquals(docId, generated.get("id"));
// and from here on down there will be lots of unchecked casting and
@@ -311,7 +312,7 @@ public class JsonWriterTestCase {
String fields = "{ \"actualMapStringToArrayOfInt\": { \"bamse\": [1, 2, 3] }}";
Document doc = readDocumentFromJson(docId, fields);
- ObjectMapper m = new ObjectMapper();
+ var m = Jackson.mapper();
Map<?, ?> generated = m.readValue(JsonWriter.toByteArray(doc), Map.class);
assertEquals(docId, generated.get("id"));
// and from here on down there will be lots of unchecked casting and
@@ -331,7 +332,7 @@ public class JsonWriterTestCase {
// we have to do everything by hand to check, as maps are unordered, but
// are serialized as an ordered structure
- ObjectMapper m = new ObjectMapper();
+ var m = Jackson.mapper();
Map<?, ?> generated = m.readValue(JsonWriter.toByteArray(doc), Map.class);
assertEquals(docId, generated.get("id"));
// and from here on down there will be lots of unchecked casting and
@@ -354,7 +355,7 @@ public class JsonWriterTestCase {
}
private void assertEqualJson(byte[] expected, byte[] generated) throws IOException {
- ObjectMapper m = new ObjectMapper();
+ var m = Jackson.mapper();
Map<?, ?> exp = m.readValue(expected, Map.class);
Map<?, ?> gen = m.readValue(generated, Map.class);
if (! exp.equals(gen)) {