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 /container-disc | |
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 'container-disc')
2 files changed, 7 insertions, 9 deletions
diff --git a/container-disc/src/main/java/com/yahoo/container/handler/observability/ApplicationStatusHandler.java b/container-disc/src/main/java/com/yahoo/container/handler/observability/ApplicationStatusHandler.java index e2cdfe7c728..f96ef1f2768 100644 --- a/container-disc/src/main/java/com/yahoo/container/handler/observability/ApplicationStatusHandler.java +++ b/container-disc/src/main/java/com/yahoo/container/handler/observability/ApplicationStatusHandler.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.container.handler.observability; +import ai.vespa.json.Jackson; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; @@ -54,7 +55,7 @@ public class ApplicationStatusHandler extends AbstractRequestHandler { Map<String, ? extends JsonNode> produceExtraFields(ApplicationStatusHandler handler); } - private static final ObjectMapper jsonMapper = new ObjectMapper(); + private static final ObjectMapper jsonMapper = Jackson.mapper(); private final JsonNode applicationJson; private final JsonNode clientsJson; @@ -271,7 +272,7 @@ public class ApplicationStatusHandler extends AbstractRequestHandler { return ret; } - private class IgnoredContent implements ContentChannel { + private static class IgnoredContent implements ContentChannel { @Override public void write(ByteBuffer buf, CompletionHandler handler) { handler.completed(); diff --git a/container-disc/src/main/java/com/yahoo/container/usability/BindingsOverviewHandler.java b/container-disc/src/main/java/com/yahoo/container/usability/BindingsOverviewHandler.java index c188f611b1d..c2e51590de4 100644 --- a/container-disc/src/main/java/com/yahoo/container/usability/BindingsOverviewHandler.java +++ b/container-disc/src/main/java/com/yahoo/container/usability/BindingsOverviewHandler.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.container.usability; +import ai.vespa.json.Jackson; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; @@ -32,7 +33,7 @@ import java.util.Map; */ public class BindingsOverviewHandler extends AbstractRequestHandler { - private static final ObjectMapper jsonMapper = new ObjectMapper(); + private static final ObjectMapper jsonMapper = Jackson.mapper(); private final JdiscBindingsConfig bindingsConfig; @@ -54,21 +55,17 @@ public class BindingsOverviewHandler extends AbstractRequestHandler { statusToReturn = com.yahoo.jdisc.Response.Status.OK; } - FastContentWriter writer = new FastContentWriter(new ResponseDispatch() { + try (FastContentWriter writer = new FastContentWriter(new ResponseDispatch() { @Override protected com.yahoo.jdisc.Response newResponse() { com.yahoo.jdisc.Response response = new com.yahoo.jdisc.Response(statusToReturn); response.headers().add("Content-Type", List.of("application/json")); return response; } - }.connect(handler)); - - try { + }.connect(handler))) { writer.write(jsonMapper.writerWithDefaultPrettyPrinter().writeValueAsBytes(json)); } catch (JsonProcessingException e) { throw new RuntimeException(e); - } finally { - writer.close(); } return new IgnoredContent(); |