You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by vy...@apache.org on 2021/05/24 19:44:38 UTC
[logging-log4j2] branch release-2.x updated: Allow JsonLayout
output JSON `null` for ContextMap (#496)
This is an automated email from the ASF dual-hosted git repository.
vy pushed a commit to branch release-2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
The following commit(s) were added to refs/heads/release-2.x by this push:
new d2895a6 Allow JsonLayout output JSON `null` for ContextMap (#496)
d2895a6 is described below
commit d2895a6b2e6de66f2fdbe85fa195c474cfd9e680
Author: Владимир Поршкевич <ne...@inbox.ru>
AuthorDate: Mon May 24 22:34:49 2021 +0300
Allow JsonLayout output JSON `null` for ContextMap (#496)
---
.../apache/logging/log4j/core/jackson/ContextDataSerializer.java | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ContextDataSerializer.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ContextDataSerializer.java
index 7ac40f0..7f9090b 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ContextDataSerializer.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ContextDataSerializer.java
@@ -52,7 +52,11 @@ public class ContextDataSerializer extends StdSerializer<ReadOnlyStringMap> {
private static final TriConsumer<String, Object, JsonGenerator> WRITE_STRING_FIELD_INTO =
(key, value, jsonGenerator) -> {
try {
- jsonGenerator.writeStringField(key, String.valueOf(value));
+ if (value == null) {
+ jsonGenerator.writeNullField(key);
+ } else {
+ jsonGenerator.writeStringField(key, String.valueOf(value));
+ }
} catch (final Exception ex) {
throw new IllegalStateException("Problem with key " + key, ex);
}