Use proper constant in JsonUtils 52/86052/1
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 28 Nov 2019 12:49:05 +0000 (13:49 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 28 Nov 2019 20:19:00 +0000 (21:19 +0100)
We are not using the Mapper here at all, just the writer. Make sure
we retain only the writer and make it a proper constant (to allow
JIT to do constant propagation).

Change-Id: I7df2a6234511c9dbf51509c495a59e642173fffe
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 7b32c396b165fbecd707afb0d8753885816eaeed)

library/impl/src/main/java/org/opendaylight/ovsdb/lib/jsonrpc/JsonUtils.java

index a0a4ddd598f2fade422a19fcf3c2af87d030cc40..a67e2807cb57efde2e5cbb2d9f6db2b078391144 100644 (file)
@@ -12,16 +12,14 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.ObjectWriter;
 
 public final class JsonUtils {
-
-    private static ObjectMapper mapper = new ObjectMapper();
-    private static ObjectWriter prettyWriter = mapper.writerWithDefaultPrettyPrinter();
+    private static final ObjectWriter PRETTY_WRITER = new ObjectMapper().writerWithDefaultPrettyPrinter();
 
     private JsonUtils() {
     }
 
-    public static String prettyString(Object jsonNode) {
+    public static String prettyString(final Object jsonNode) {
         try {
-            return prettyWriter.writeValueAsString(jsonNode);
+            return PRETTY_WRITER.writeValueAsString(jsonNode);
         } catch (JsonProcessingException e) {
             throw new RuntimeException(e);
         }