Add custom message serializer for JsonLayout

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Add custom message serializer for JsonLayout

Franz Wong
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());

}


}