For example, here is the psuedo code:
Code: Select all
@Provider
@Consumes(MEDIA_TYPE.JSON)
public class JSONMessageBodyReader implements MessageBodyReader<MathTable>{
....
public MathTable readFrom(Class type, Type genericType, Annotation[] annotations, MediaType mediaType,
MultivaluedMap httpHeaders, InputStream is) throws IOException, WebApplicationException
{
ObjectInputStream ois = new ObjectInputStream(is);
//do some more steps to convert the input JSON string in the input stream into a JSON object...
return (MathTable)ois.readObject();
}
....
}
Code: Select all
@Provider
@Produce(MEDIA_TYPE.JSON)
public class JSONMessageBodyWriter implements MessageBodyWriter<MathTable>{
public void writeTo(MathTable mathTable, Class<?> type, Type genericType, Annotation[] annotations,
MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream os) throws
IOException, WebApplicationException
{
//do some steps to convert a MathTable object into a JSON string and write it to an output stream...
ObjectOutputStream oos = new ObjectOutputStream(os);
oos.writeObject(mathTable);
}
Since we can provide the customized MessageBodyWriter and MessageBodyReader, the answer can be "all of the above".
Any comments?