@Test void testEncodeJsonUtf16() throws IOException { assertEquals( Unpooled.copiedBuffer("{\"name\":\"foo\"}", Charset.forName("UTF-16")), jsonEncoder.encode(Unpooled.directBuffer(), "utf-16, foo-bar", new Person("foo"))); }
@Override public ByteBuf encode(ByteBuf buf, CharSequence acceptCharset, Object object) throws IOException { try (OutputStreamWriter writer = new OutputStreamWriter(new ByteBufOutputStream(buf), charset(acceptCharset))) { if (object instanceof MessageOrBuilder) { String json = printer.print((MessageOrBuilder) object); writer.write(json); } else { mapper.writeValue(writer, object); } return buf; } }
JsonEncoder implements Encoder { @Override public ByteBuf encode(ByteBuf buf, CharSequence acceptCharset, Object object) throws IOException { try (OutputStreamWriter writer = new OutputStreamWriter(new ByteBufOutputStream(buf), charset(acceptCharset))) { if (object instanceof MessageOrBuilder) { String json = printer.print((MessageOrBuilder) object); writer.write(json); } else { mapper.writeValue(writer, object); } return buf; } } }
JsonEncoder implements Encoder { @Override public ByteBuf encode(ByteBuf buf, CharSequence acceptCharset, Object object) throws IOException { try (OutputStreamWriter writer = new OutputStreamWriter(new ByteBufOutputStream(buf), charset(acceptCharset))) { if (object instanceof MessageOrBuilder) { String json = printer.print((MessageOrBuilder) object); writer.write(json); } else { mapper.writeValue(writer, object); } return buf; } }  }
JsonEncoder implements Encoder { @Override public ByteBuf encode(ByteBuf buf, CharSequence acceptCharset, Object object) throws IOException { try (OutputStreamWriter writer = new OutputStreamWriter(new ByteBufOutputStream(buf), charset(acceptCharset))) { if (object instanceof MessageOrBuilder) { String json = printer.print((MessageOrBuilder) object); writer.write(json); } else { mapper.writeValue(writer, object); } return buf; } }  CharSequence mediaType(); @Override ByteBuf encode(ByteBuf buf, CharSequence acceptCharset, Object object); @Override Charset charset(CharSequence acceptCharset); }
JsonEncoder implements Encoder { @Override public ByteBuf encode(ByteBuf buf, CharSequence acceptCharset, Object object) throws IOException { try (OutputStreamWriter writer = new OutputStreamWriter(new ByteBufOutputStream(buf), charset(acceptCharset))) { if (object instanceof MessageOrBuilder) { String json = printer.print((MessageOrBuilder) object); writer.write(json); } else { mapper.writeValue(writer, object); } return buf; } }  CharSequence mediaType(); @Override ByteBuf encode(ByteBuf buf, CharSequence acceptCharset, Object object); @Override Charset charset(CharSequence acceptCharset); static final Charset DEFAULT_CHARSET; }