SOLR-14129: Reuse Jackson ObjectMapper in AuditLoggerPlugin (#1104)

This commit is contained in:
Jan Høydahl 2019-12-30 17:40:32 +01:00 committed by GitHub
parent 43e30f9665
commit c4993bc99c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 3 deletions

View File

@ -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)

View File

@ -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);