package ch.qos.logback.classic; import ch.qos.logback.classic.spi.ILoggingEvent; import ch.qos.logback.classic.spi.IThrowableProxy; import ch.qos.logback.classic.spi.LoggerContextVO; import ch.qos.logback.classic.spi.LoggingEventVO; import org.junit.Test; import org.slf4j.Marker; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.Map; import static org.junit.Assert.assertEquals; public class LoggingEventVOSerializationTest { @Test public void serializingArray() throws IOException, ClassNotFoundException { LoggingEventVO le= LoggingEventVO.build(new MyLoggingEvent()); ByteArrayOutputStream bos=new ByteArrayOutputStream(); ObjectOutputStream oos=new ObjectOutputStream(bos); oos.writeObject(le); oos.close(); ByteArrayInputStream bis=new ByteArrayInputStream(bos.toByteArray()); ObjectInputStream ois=new ObjectInputStream(bis); LoggingEventVO read= (LoggingEventVO) ois.readObject(); Object[] args = read.getArgumentArray(); assertEquals(3, args.length); assertEquals("One", args[0]); assertEquals("Two", args[1]); assertEquals("[Three, Four, Five]", args[2]); } public static class MyLoggingEvent implements ILoggingEvent { public String getThreadName() { return "Mock"; } public Level getLevel() { return Level.DEBUG; } public String getMessage() { return "Message: {}, {}, {}"; } public Object[] getArgumentArray() { return new Object[]{"One", "Two", new String[]{"Three", "Four", "Five"}}; } public String getFormattedMessage() { return "Message: One, Two, [Three, Four, Five]"; } public String getLoggerName() { return "Mock"; } public LoggerContextVO getLoggerContextVO() { return null; } public IThrowableProxy getThrowableProxy() { return null; } public StackTraceElement[] getCallerData() { return new StackTraceElement[0]; } public boolean hasCallerData() { return false; } public Marker getMarker() { return null; } public Map getMDCPropertyMap() { return null; } public long getTimeStamp() { return 0; } public void prepareForDeferredProcessing() { } } }