001/* 002 * Logback: the reliable, generic, fast and flexible logging framework. 003 * Copyright (C) 1999-2026, QOS.ch. All rights reserved. 004 * 005 * This program and the accompanying materials are dual-licensed under 006 * either the terms of the Eclipse Public License v2.0 as published by 007 * the Eclipse Foundation 008 * 009 * or (per the licensee's choosing) 010 * 011 * under the terms of the GNU Lesser General Public License version 2.1 012 * as published by the Free Software Foundation. 013 */ 014package ch.qos.logback.classic.kryo; 015 016import ch.qos.logback.core.kryo.SerializerBase; 017import com.esotericsoftware.kryo.kryo5.Kryo; 018import com.esotericsoftware.kryo.kryo5.io.Input; 019import com.esotericsoftware.kryo.kryo5.io.Output; 020import org.slf4j.event.KeyValuePair; 021 022public class KeyValuePairSerializer extends SerializerBase<KeyValuePair> { 023 024 025 public KeyValuePairSerializer() { 026 super(BiMapType.NONE, 0); 027 } 028 029 @Override 030 protected void writeNewEntry(Kryo kryo, Output output, KeyValuePair keyValuePair) { 031 output.writeString(keyValuePair.key); 032 Object nonNullAllowedObject = SafeObjectTransformer.asAllowedNonNullObject(keyValuePair.value); 033 kryo.writeClassAndObject(output, nonNullAllowedObject); 034 } 035 036 037 @Override 038 protected KeyValuePair readNewEntry(Kryo kryo, Input input) { 039 String key = input.readString(); 040 //System.out.println("Deserializing KeyValuePair with key: " + key); 041 Object value = kryo.readClassAndObject(input); 042 // a null value is written as NULL_PROXY 043 if (SafeObjectTransformer.NULL_PROXY.equals(value)) { 044 value = null; 045 } 046 return new KeyValuePair(key, value); 047 } 048}