@Test public void testEncode2() throws Exception { Object o = new Object(); JsonEncoder jsonEncoder = new JsonEncoder(SwallowMessage.class); Assert.assertEquals(o, jsonEncoder.encode(null, null, o)); }
@Override protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { if (msg.getClass() == clazz) { JsonBinder jsonBinder = JsonBinder.getNonEmptyBinder(); String json = jsonBinder.toJson(msg); byte[] jsonBytes = json.getBytes(Charset.forName("UTF-8")); ChannelBuffer channelBuffer = ChannelBuffers.buffer(jsonBytes.length); channelBuffer.writeBytes(jsonBytes); return channelBuffer; } return msg; }
JsonEncoder extends OneToOneEncoder { @Override protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { if (msg.getClass() == clazz) { JsonBinder jsonBinder = JsonBinder.getNonEmptyBinder(); String json = jsonBinder.toJson(msg); byte[] jsonBytes = json.getBytes(Charset.forName("UTF-8")); ChannelBuffer channelBuffer = ChannelBuffers.buffer(jsonBytes.length); channelBuffer.writeBytes(jsonBytes); return channelBuffer; } return msg; } }
JsonEncoder extends OneToOneEncoder { @Override protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { if (msg.getClass() == clazz) { JsonBinder jsonBinder = JsonBinder.getNonEmptyBinder(); String json = jsonBinder.toJson(msg); byte[] jsonBytes = json.getBytes(Charset.forName("UTF-8")); ChannelBuffer channelBuffer = ChannelBuffers.buffer(jsonBytes.length); channelBuffer.writeBytes(jsonBytes); return channelBuffer; } return msg; } JsonEncoder(Class clazz); }
JsonEncoder extends OneToOneEncoder { @Override protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { if (msg.getClass() == clazz) { JsonBinder jsonBinder = JsonBinder.getNonEmptyBinder(); String json = jsonBinder.toJson(msg); byte[] jsonBytes = json.getBytes(Charset.forName("UTF-8")); ChannelBuffer channelBuffer = ChannelBuffers.buffer(jsonBytes.length); channelBuffer.writeBytes(jsonBytes); return channelBuffer; } return msg; } JsonEncoder(Class clazz);  }
JsonEncoder extends OneToOneEncoder { @Override protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { if (msg.getClass() == clazz) { JsonBinder jsonBinder = JsonBinder.getNonEmptyBinder(); String json = jsonBinder.toJson(msg); byte[] jsonBytes = json.getBytes(Charset.forName("UTF-8")); ChannelBuffer channelBuffer = ChannelBuffers.buffer(jsonBytes.length); channelBuffer.writeBytes(jsonBytes); return channelBuffer; } return msg; } JsonEncoder(Class clazz);   }