diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2023-11-23 16:07:43 +0100 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2023-11-23 16:12:51 +0100 |
commit | ef535f6c51393d945d9fe07de38de224d5ae443f (patch) | |
tree | 2f5976537a200aebbf6644b8e1ef93f2c669319d /flags | |
parent | f966346429c85fc31c8ea962b518e02a19f77f46 (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 'flags')
6 files changed, 16 insertions, 13 deletions
diff --git a/flags/src/main/java/com/yahoo/vespa/flags/JsonNodeRawFlag.java b/flags/src/main/java/com/yahoo/vespa/flags/JsonNodeRawFlag.java index 3441c3707fd..f2bc90a487e 100644 --- a/flags/src/main/java/com/yahoo/vespa/flags/JsonNodeRawFlag.java +++ b/flags/src/main/java/com/yahoo/vespa/flags/JsonNodeRawFlag.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.vespa.flags; +import ai.vespa.json.Jackson; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; @@ -86,7 +87,7 @@ public class JsonNodeRawFlag implements RawFlag { // ObjectMapper is a heavy-weight object so we construct it only when we need it return mapper.updateAndGet((objectMapper) -> { if (objectMapper != null) return objectMapper; - return new ObjectMapper(); + return Jackson.mapper(); }); } diff --git a/flags/src/main/java/com/yahoo/vespa/flags/json/wire/WireFlagData.java b/flags/src/main/java/com/yahoo/vespa/flags/json/wire/WireFlagData.java index 5a2a4e56559..cf2cb6795ee 100644 --- a/flags/src/main/java/com/yahoo/vespa/flags/json/wire/WireFlagData.java +++ b/flags/src/main/java/com/yahoo/vespa/flags/json/wire/WireFlagData.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.vespa.flags.json.wire; +import ai.vespa.json.Jackson; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; @@ -24,7 +25,7 @@ public class WireFlagData { @JsonProperty("rules") public List<WireRule> rules; @JsonProperty("attributes") public Map<String, String> defaultFetchVector; - private static final ObjectMapper mapper = new ObjectMapper(); + private static final ObjectMapper mapper = Jackson.mapper(); public byte[] serializeToBytes() { return uncheck(() -> mapper.writeValueAsBytes(this)); diff --git a/flags/src/main/java/com/yahoo/vespa/flags/json/wire/WireFlagDataList.java b/flags/src/main/java/com/yahoo/vespa/flags/json/wire/WireFlagDataList.java index e7c3ce1a6f6..1e18b36a531 100644 --- a/flags/src/main/java/com/yahoo/vespa/flags/json/wire/WireFlagDataList.java +++ b/flags/src/main/java/com/yahoo/vespa/flags/json/wire/WireFlagDataList.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.vespa.flags.json.wire; +import ai.vespa.json.Jackson; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; @@ -21,7 +22,7 @@ public class WireFlagDataList { @JsonProperty("flags") public List<WireFlagData> flags = new ArrayList<>(); - private static final ObjectMapper mapper = new ObjectMapper(); + private static final ObjectMapper mapper = Jackson.mapper(); public void serializeToOutputStream(OutputStream outputStream) { uncheck(() -> mapper.writeValue(outputStream, this)); diff --git a/flags/src/test/java/com/yahoo/vespa/flags/custom/ClusterCapacityTest.java b/flags/src/test/java/com/yahoo/vespa/flags/custom/ClusterCapacityTest.java index 1d2e550aa7a..e078506ce21 100644 --- a/flags/src/test/java/com/yahoo/vespa/flags/custom/ClusterCapacityTest.java +++ b/flags/src/test/java/com/yahoo/vespa/flags/custom/ClusterCapacityTest.java @@ -1,7 +1,7 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.flags.custom; -import com.fasterxml.jackson.databind.ObjectMapper; +import ai.vespa.json.Jackson; import org.junit.jupiter.api.Test; import java.io.IOException; @@ -13,7 +13,7 @@ public class ClusterCapacityTest { @Test void serialization() throws IOException { ClusterCapacity clusterCapacity = new ClusterCapacity(7, 1.2, 3.4, 5.6, null, "fast", "local", "x86_64", null); - ObjectMapper mapper = new ObjectMapper(); + var mapper = Jackson.mapper(); String json = mapper.writeValueAsString(clusterCapacity); assertEquals(""" {"count":7,"vcpu":1.2,"memoryGb":3.4,"diskGb":5.6,"diskSpeed":"fast","storageType":"local","architecture":"x86_64"}""", @@ -33,7 +33,7 @@ public class ClusterCapacityTest { @Test void serialization2() throws IOException { ClusterCapacity clusterCapacity = new ClusterCapacity(7, 1.2, 3.4, 5.6, 2.3, "any", "remote", "arm64", null); - ObjectMapper mapper = new ObjectMapper(); + var mapper = Jackson.mapper(); String json = mapper.writeValueAsString(clusterCapacity); assertEquals(""" {"count":7,"vcpu":1.2,"memoryGb":3.4,"diskGb":5.6,"bandwidthGbps":2.3,"diskSpeed":"any","storageType":"remote","architecture":"arm64"}""", @@ -53,7 +53,7 @@ public class ClusterCapacityTest { @Test void serialization3() throws IOException { ClusterCapacity clusterCapacity = new ClusterCapacity(7, 1.2, 3.4, 5.6, 2.3, "any", "remote", "arm64", "admin"); - ObjectMapper mapper = new ObjectMapper(); + var mapper = Jackson.mapper(); String json = mapper.writeValueAsString(clusterCapacity); assertEquals(""" {"count":7,"vcpu":1.2,"memoryGb":3.4,"diskGb":5.6,"bandwidthGbps":2.3,"diskSpeed":"any","storageType":"remote","architecture":"arm64","clusterType":"admin"}""", @@ -74,7 +74,7 @@ public class ClusterCapacityTest { @Test void serializationWithNoNodeResources() throws IOException { ClusterCapacity clusterCapacity = new ClusterCapacity(7, null, null, null, null, null, null, null, null); - ObjectMapper mapper = new ObjectMapper(); + var mapper = Jackson.mapper(); String json = mapper.writeValueAsString(clusterCapacity); assertEquals("{\"count\":7,\"diskSpeed\":\"fast\",\"storageType\":\"any\",\"architecture\":\"x86_64\"}", json); diff --git a/flags/src/test/java/com/yahoo/vespa/flags/custom/SharedHostTest.java b/flags/src/test/java/com/yahoo/vespa/flags/custom/SharedHostTest.java index 45145923ab9..66edad3fe36 100644 --- a/flags/src/test/java/com/yahoo/vespa/flags/custom/SharedHostTest.java +++ b/flags/src/test/java/com/yahoo/vespa/flags/custom/SharedHostTest.java @@ -1,7 +1,7 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.flags.custom; -import com.fasterxml.jackson.databind.ObjectMapper; +import ai.vespa.json.Jackson; import org.junit.jupiter.api.Test; import java.io.IOException; @@ -21,7 +21,7 @@ public class SharedHostTest { } private void verifySerialization(SharedHost sharedHost) throws IOException { - ObjectMapper mapper = new ObjectMapper(); + var mapper = Jackson.mapper(); String json = mapper.writeValueAsString(sharedHost); SharedHost deserialized = mapper.readValue(json, SharedHost.class); assertEquals(sharedHost, deserialized); diff --git a/flags/src/test/java/com/yahoo/vespa/flags/json/SerializationTest.java b/flags/src/test/java/com/yahoo/vespa/flags/json/SerializationTest.java index 6f4a4ff4e63..6e2b4b80d4b 100644 --- a/flags/src/test/java/com/yahoo/vespa/flags/json/SerializationTest.java +++ b/flags/src/test/java/com/yahoo/vespa/flags/json/SerializationTest.java @@ -1,7 +1,7 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.flags.json; -import com.fasterxml.jackson.databind.ObjectMapper; +import ai.vespa.json.Jackson; import com.fasterxml.jackson.databind.node.JsonNodeType; import com.yahoo.vespa.flags.json.wire.WireCondition; import com.yahoo.vespa.flags.json.wire.WireFlagData; @@ -98,8 +98,8 @@ public class SerializationTest { assertThat(wireData.defaultFetchVector.get("node-type"), equalTo("nt1")); // Verify serialization of RawFlag == serialization by ObjectMapper - ObjectMapper mapper = new ObjectMapper(); - String serializedWithObjectMapper = mapper.writeValueAsString(mapper.readTree(json)); + var mapper = Jackson.mapper(); + String serializedWithObjectMapper = Jackson.mapper().writeValueAsString(mapper.readTree(json)); assertThat(wireData.serializeToJson(), equalTo(serializedWithObjectMapper)); // Unfortunately the order of attributes members are different... |