HessianSerializer implements MessageBodyWriter<Object> { @Override public void writeTo(Object t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { Hessian2StreamingOutput out = new Hessian2StreamingOutput(entityStream); out.writeObject(t); out.flush(); }  @Override boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override long getSize(Object t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override void writeTo(Object t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream);  }
@Test public void serialize() throws Exception{ String expected = "Hey Duke!"; ByteArrayOutputStream bois = new ByteArrayOutputStream(); cut.writeTo(expected, null, null, null, MediaType.WILDCARD_TYPE, null, bois); final byte[] content = bois.toByteArray(); ByteArrayInputStream bais = new ByteArrayInputStream(content); Hessian2StreamingInput inputStream = new Hessian2StreamingInput(bais); String actual = (String) inputStream.readObject(); assertThat(actual,is(expected)); }