Search in sources :

Example 6 with Log4jStackTraceElementDeserializer

use of org.apache.logging.log4j.jackson.Log4jStackTraceElementDeserializer in project logging-log4j2 by apache.

the class StackTraceElementJsonMixInTest method testFromJsonWithSimpleModule.

@Test
public void testFromJsonWithSimpleModule() throws Exception {
    final ObjectMapper mapper = new ObjectMapper();
    final SimpleModule module = new SimpleModule();
    module.addDeserializer(StackTraceElement.class, new Log4jStackTraceElementDeserializer());
    mapper.registerModule(module);
    final StackTraceElement expected = new StackTraceElement("package.SomeClass", "someMethod", "SomeClass.java", 123);
    final String s = this.aposToQuotes("{'class':'package.SomeClass','method':'someMethod','file':'SomeClass.java','line':123}");
    final StackTraceElement actual = mapper.readValue(s, StackTraceElement.class);
    Assert.assertEquals(expected, actual);
}
Also used : Log4jStackTraceElementDeserializer(org.apache.logging.log4j.jackson.Log4jStackTraceElementDeserializer) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) Test(org.junit.Test)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 Log4jStackTraceElementDeserializer (org.apache.logging.log4j.jackson.Log4jStackTraceElementDeserializer)6 Test (org.junit.Test)6 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)5 YAMLMapper (com.fasterxml.jackson.dataformat.yaml.YAMLMapper)2