UrlFormEncodedBodyWriter implements MessageBodyWriter<Object> { @Override public void writeTo(Object o, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { Map<String, Object> m = new HashMap<>(); beansConverter.copy(o, m); String encoded = CodecUtils.formEncode(m); entityStream.write(encoded.getBytes()); }  @Override boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override void writeTo(Object o, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream);  }
@Test public void test() throws IOException { EnkanSystem system = EnkanSystem.of("beans", new JacksonBeansConverter()); system.start(); Map<String, SystemComponent> components = new HashMap<String, SystemComponent>() {{ put("beans", system.getComponent("beans")); }}; ComponentInjector injector = new ComponentInjector(components); UrlFormEncodedBodyWriter bodyWriter = new UrlFormEncodedBodyWriter(); injector.inject(bodyWriter); TestDto dto = new TestDto(); dto.setA(8); dto.setB("あいうえお"); try(ByteArrayOutputStream entityStream = new ByteArrayOutputStream()) { bodyWriter.writeTo(dto, TestDto.class, TestDto.class, null, new MediaType("", ""), new MultivaluedHashMap<>(), entityStream); String out = new String(entityStream.toByteArray()); Parameters params = CodecUtils.formDecode(out, "UTF-8"); assertThat(params.getLong("a")).isEqualTo(8); assertThat(params.get("b")).isEqualTo("あいうえお"); } }