/** * Creates a new EventMessageWriter writing data to the specified underlying {@code output}. * * @param output the underlying output * @param serializer The serializer to deserialize payload and metadata with */ public EventMessageWriter(DataOutput output, Serializer serializer) { this.out = output; this.serializer = new MessageSerializer(serializer); }
Gson gson = new GsonBuilder() .registerTypeAdapter(MessageFromWebservice.class, new MessageSerializer()) .create();
public static void main(String[] args) { Gson gson = new GsonBuilder() .registerTypeAdapter(Message.class, new MessageSerializer()) .setPrettyPrinting() .create(); String json = gson.toJson( new InfoMessage( new AlertMessage( new ErrorMessage(null, "the error message"), "the alert message"), "the info message"), Message.class); System.out.println(json); }