logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Franz Wong <franzw...@gmail.com>
Subject Add custom message serializer for JsonLayout
Date Thu, 04 Jan 2018 02:03:53 GMT
Hi,

I tried to add a custom message serializer for JsonLayout. But it keeps
using the default "MessageSerializer". So how can I create a custom message
serializer? Thanks.

-Franz

Here is my code

"JsonObjectMessage"

@JsonSerialize(using = JsonObjectMessageSerializer.class)

public class JsonObjectMessage extends ObjectMessage {

private static final long serialVersionUID = 1L;


public JsonObjectMessage(Object obj) {

super(obj);

}

}

"JsonObjectMessageSerializer"

public class JsonObjectMessageSerializer extends
StdScalarSerializer<JsonObjectMessage>
{


private static final long serialVersionUID = 1L;


protected JsonObjectMessageSerializer() {

super(JsonObjectMessage.class);

}


@Override

public void serialize(JsonObjectMessage message, JsonGenerator gen,
SerializerProvider provider) throws IOException {

gen.writeObject(message.getParameter());

}


}

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message