From af2e4018c92b0fb311f60dfe507335b12e2935a4 Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Fri, 13 Sep 2019 12:14:25 -0400 Subject: Extract YamlJsonTranslator from StandardYamlCoder Refactored StandardYamlCoder, extracting a new class, YamlJsonTranslator, from it. This facilitates performing yaml translation when not using a standard "gson" coder. Added YamlJacksonHandler which supports YAML translation layered on top of a JacksonHandler instead of a GsonMessageBodyHandler. Also added junit tests to complete coverage of StandardCoder. Also added public APPLICATION_YAML to YamlMessageBodyHandler. Change-Id: Ia470fa194661fbf1aebeaf0f18b57f2a984cb64b Issue-ID: POLICY-2081 Signed-off-by: Jim Hahn --- .../onap/policy/common/gson/GsonMessageBodyHandler.java | 14 ++++++++++++-- .../java/org/onap/policy/common/gson/JacksonHandler.java | 4 +--- 2 files changed, 13 insertions(+), 5 deletions(-) (limited to 'gson/src/main/java') diff --git a/gson/src/main/java/org/onap/policy/common/gson/GsonMessageBodyHandler.java b/gson/src/main/java/org/onap/policy/common/gson/GsonMessageBodyHandler.java index a36f8a07..ad270910 100644 --- a/gson/src/main/java/org/onap/policy/common/gson/GsonMessageBodyHandler.java +++ b/gson/src/main/java/org/onap/policy/common/gson/GsonMessageBodyHandler.java @@ -62,9 +62,17 @@ public class GsonMessageBodyHandler implements MessageBodyReader, Messag * into Integer/Long, where possible. */ public GsonMessageBodyHandler() { - this(new GsonBuilder().registerTypeAdapterFactory(new MapDoubleAdapterFactory()).create()); + this(new GsonBuilder()); + } - logger.info("Using GSON for REST calls"); + /** + * Constructs the object, using a Gson object that translates Doubles inside of Maps + * into Integer/Long, where possible. + * + * @param builder builder to use to create the gson object + */ + public GsonMessageBodyHandler(GsonBuilder builder) { + this(builder.registerTypeAdapterFactory(new MapDoubleAdapterFactory()).create()); } /** @@ -74,6 +82,8 @@ public class GsonMessageBodyHandler implements MessageBodyReader, Messag */ public GsonMessageBodyHandler(Gson gson) { this.gson = gson; + + logger.info("Using GSON for REST calls"); } @Override diff --git a/gson/src/main/java/org/onap/policy/common/gson/JacksonHandler.java b/gson/src/main/java/org/onap/policy/common/gson/JacksonHandler.java index ad9692f4..6d946439 100644 --- a/gson/src/main/java/org/onap/policy/common/gson/JacksonHandler.java +++ b/gson/src/main/java/org/onap/policy/common/gson/JacksonHandler.java @@ -49,9 +49,7 @@ public class JacksonHandler extends GsonMessageBodyHandler { super(builder .registerTypeAdapterFactory(new JacksonFieldAdapterFactory()) .registerTypeAdapterFactory(new JacksonMethodAdapterFactory()) - .registerTypeAdapterFactory(new MapDoubleAdapterFactory()) - .setExclusionStrategies(new JacksonExclusionStrategy()) - .create()); + .setExclusionStrategies(new JacksonExclusionStrategy())); } } -- cgit 1.2.3-korg