From ef535f6c51393d945d9fe07de38de224d5ae443f Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Thu, 23 Nov 2023 16:07:43 +0100 Subject: 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. --- .../handler/observability/ApplicationStatusHandler.java | 5 +++-- .../yahoo/container/usability/BindingsOverviewHandler.java | 11 ++++------- 2 files changed, 7 insertions(+), 9 deletions(-) (limited to 'container-disc') 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 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(); -- cgit v1.2.3