@Test public void testDecode() throws Exception { DemoBean demoBean = new DemoBean(); demoBean.setA(1); demoBean.setB("b"); SwallowMessage message = new SwallowMessage(); message.setContent(demoBean); HashMap<String, String> map = new HashMap<String, String>(); map.put("property-key", "property-value"); message.setProperties(map); JsonBinder jsonBinder = JsonBinder.getNonEmptyBinder(); String json = jsonBinder.toJson(message); JsonDecoder jsonDecoder = new JsonDecoder(SwallowMessage.class); Message actualMessage = (Message) jsonDecoder.decode(null, null, ChannelBuffers.wrappedBuffer(json.getBytes("UTF-8"))); Assert.assertEquals(message, actualMessage); }
@SuppressWarnings("unchecked") @Override protected Object decode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { if (!(msg instanceof ChannelBuffer)) { return msg; } ChannelBuffer buf = (ChannelBuffer) msg; String json = buf.toString(Charset.forName("UTF-8")); JsonBinder jsonBinder = JsonBinder.getNonEmptyBinder(); return jsonBinder.fromJson(json, clazz); }
JsonDecoder extends OneToOneDecoder { @SuppressWarnings("unchecked") @Override protected Object decode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { if (!(msg instanceof ChannelBuffer)) { return msg; } ChannelBuffer buf = (ChannelBuffer) msg; String json = buf.toString(Charset.forName("UTF-8")); JsonBinder jsonBinder = JsonBinder.getNonEmptyBinder(); return jsonBinder.fromJson(json, clazz); } }
JsonDecoder extends OneToOneDecoder { @SuppressWarnings("unchecked") @Override protected Object decode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { if (!(msg instanceof ChannelBuffer)) { return msg; } ChannelBuffer buf = (ChannelBuffer) msg; String json = buf.toString(Charset.forName("UTF-8")); JsonBinder jsonBinder = JsonBinder.getNonEmptyBinder(); return jsonBinder.fromJson(json, clazz); } JsonDecoder(Class clazz); }
JsonDecoder extends OneToOneDecoder { @SuppressWarnings("unchecked") @Override protected Object decode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { if (!(msg instanceof ChannelBuffer)) { return msg; } ChannelBuffer buf = (ChannelBuffer) msg; String json = buf.toString(Charset.forName("UTF-8")); JsonBinder jsonBinder = JsonBinder.getNonEmptyBinder(); return jsonBinder.fromJson(json, clazz); } JsonDecoder(Class clazz);  }
JsonDecoder extends OneToOneDecoder { @SuppressWarnings("unchecked") @Override protected Object decode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { if (!(msg instanceof ChannelBuffer)) { return msg; } ChannelBuffer buf = (ChannelBuffer) msg; String json = buf.toString(Charset.forName("UTF-8")); JsonBinder jsonBinder = JsonBinder.getNonEmptyBinder(); return jsonBinder.fromJson(json, clazz); } JsonDecoder(Class clazz);   }