Search in sources :

Example 1 with Log4jStackTraceElementDeserializer

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

the class StackTraceElementYamlMixInTest method testFromYamlWithLog4jModule.

@Test
public void testFromYamlWithLog4jModule() throws Exception {
    final ObjectMapper mapper = new YAMLMapper();
    final boolean encodeThreadContextAsList = false;
    final SimpleModule module = new Log4jYamlModule(encodeThreadContextAsList, true, false);
    module.addDeserializer(StackTraceElement.class, new Log4jStackTraceElementDeserializer());
    mapper.registerModule(module);
    final StackTraceElement expected = new StackTraceElement("package.SomeClass", "someMethod", "SomeClass.java", 123);
    final StackTraceElement actual = mapper.readValue("---\nclass: package.SomeClass\nmethod: someMethod\nfile: SomeClass.java\nline: 123\n...", StackTraceElement.class);
    Assert.assertEquals(expected, actual);
}
Also used : Log4jStackTraceElementDeserializer(org.apache.logging.log4j.jackson.Log4jStackTraceElementDeserializer) YAMLMapper(com.fasterxml.jackson.dataformat.yaml.YAMLMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) Test(org.junit.Test)

Example 2 with Log4jStackTraceElementDeserializer

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

the class StackTraceElementJsonMixInTest method testFromJsonWithLog4jModule.

@Test
public void testFromJsonWithLog4jModule() throws Exception {
    final ObjectMapper mapper = new ObjectMapper();
    final boolean encodeThreadContextAsList = false;
    final SimpleModule module = new Log4jJsonModule(encodeThreadContextAsList, true, false, false);
    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)

Example 3 with Log4jStackTraceElementDeserializer

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

the class StackTraceElementXmlMixInTest method testFromJsonWithLog4jModule.

@Test
public void testFromJsonWithLog4jModule() throws Exception {
    final ObjectMapper mapper = new ObjectMapper();
    final boolean encodeThreadContextAsList = false;
    final Log4jXmlModule module = new Log4jXmlModule(true, false);
    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) Test(org.junit.Test)

Example 4 with Log4jStackTraceElementDeserializer

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

the class StackTraceElementXmlMixInTest 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)

Example 5 with Log4jStackTraceElementDeserializer

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

the class StackTraceElementYamlMixInTest method testFromYamlWithSimpleModule.

@Test
public void testFromYamlWithSimpleModule() throws Exception {
    final ObjectMapper mapper = new YAMLMapper();
    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 StackTraceElement actual = mapper.readValue("---\nclass: package.SomeClass\nmethod: someMethod\nfile: SomeClass.java\nline: 123\n...", StackTraceElement.class);
    Assert.assertEquals(expected, actual);
}
Also used : Log4jStackTraceElementDeserializer(org.apache.logging.log4j.jackson.Log4jStackTraceElementDeserializer) YAMLMapper(com.fasterxml.jackson.dataformat.yaml.YAMLMapper) 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