From c4993bc99ca4e9b1780c900e8bfa242d540ff8b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20H=C3=B8ydahl?= Date: Mon, 30 Dec 2019 17:40:32 +0100 Subject: [PATCH] SOLR-14129: Reuse Jackson ObjectMapper in AuditLoggerPlugin (#1104) --- solr/CHANGES.txt | 2 ++ .../java/org/apache/solr/security/AuditLoggerPlugin.java | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index dee2daf5280..f124612c148 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -182,6 +182,8 @@ Improvements * SOLR-13808: filter in BoolQParser and {"bool":{"filter":..}} in Query DSL are cached by default (Mikhail Khludnev) +* SOLR-14129: Reuse Jackson ObjectMapper in AuditLoggerPlugin (janhoy) + Optimizations --------------------- (No changes) diff --git a/solr/core/src/java/org/apache/solr/security/AuditLoggerPlugin.java b/solr/core/src/java/org/apache/solr/security/AuditLoggerPlugin.java index c3ff2546b21..44d10ecc33b 100644 --- a/solr/core/src/java/org/apache/solr/security/AuditLoggerPlugin.java +++ b/solr/core/src/java/org/apache/solr/security/AuditLoggerPlugin.java @@ -283,14 +283,15 @@ public abstract class AuditLoggerPlugin implements Closeable, Runnable, SolrInfo * Event formatter that returns event as JSON string */ public static class JSONAuditEventFormatter implements AuditEventFormatter { + private static ObjectMapper mapper = new ObjectMapper() + .configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false) + .setSerializationInclusion(Include.NON_NULL); + /** * Formats an audit event as a JSON string */ @Override public String formatEvent(AuditEvent event) { - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); - mapper.setSerializationInclusion(Include.NON_NULL); try { StringWriter sw = new StringWriter(); mapper.writeValue(sw, event);