|
16 | 16 | */
|
17 | 17 | package org.apache.logging.log4j.layout.template.json;
|
18 | 18 |
|
| 19 | +import java.util.LinkedHashMap; |
| 20 | +import java.util.Map; |
| 21 | +import java.util.function.BiConsumer; |
| 22 | +import java.util.function.Consumer; |
| 23 | + |
19 | 24 | import org.apache.logging.log4j.Level;
|
20 | 25 | import org.apache.logging.log4j.core.Layout;
|
21 | 26 | import org.apache.logging.log4j.core.LogEvent;
|
|
31 | 36 | import org.apache.logging.log4j.layout.template.json.util.JsonWriter;
|
32 | 37 | import org.apache.logging.log4j.layout.template.json.util.MapAccessor;
|
33 | 38 |
|
34 |
| -import java.util.LinkedHashMap; |
35 |
| -import java.util.Map; |
36 |
| -import java.util.function.BiConsumer; |
37 |
| -import java.util.function.Consumer; |
38 |
| - |
39 | 39 | public final class TestHelpers {
|
40 | 40 |
|
41 | 41 | public static final Configuration CONFIGURATION = new DefaultConfiguration();
|
@@ -74,11 +74,18 @@ public static void usingSerializedLogEventAccessor(
|
74 | 74 | final LogEvent logEvent,
|
75 | 75 | final Consumer<MapAccessor> accessorConsumer) {
|
76 | 76 | final String serializedLogEventJson = layout.toSerializable(logEvent);
|
77 |
| - @SuppressWarnings("unchecked") |
78 |
| - final Map<String, Object> deserializedLogEvent = |
79 |
| - (Map<String, Object>) readJson(serializedLogEventJson); |
80 |
| - final MapAccessor serializedLogEventAccessor = new MapAccessor(deserializedLogEvent); |
81 |
| - accessorConsumer.accept(serializedLogEventAccessor); |
| 77 | + |
| 78 | + try { |
| 79 | + @SuppressWarnings("unchecked") |
| 80 | + final Map<String, Object> deserializedLogEvent = |
| 81 | + (Map<String, Object>) readJson(serializedLogEventJson); |
| 82 | + |
| 83 | + final MapAccessor serializedLogEventAccessor = new MapAccessor(deserializedLogEvent); |
| 84 | + accessorConsumer.accept(serializedLogEventAccessor); |
| 85 | + } catch (Exception e) { |
| 86 | + throw new RuntimeException("failed to deserialize log event (" + e |
| 87 | + + "). Serialized Log Event:\n" + serializedLogEventJson); |
| 88 | + } |
82 | 89 | }
|
83 | 90 |
|
84 | 91 | public static Object readJson(final String json) {
|
|
0 commit comments