Java Reference
In-Depth Information
public
public boolean
boolean isReadable ( Class type , Type genericType ,
Annotation [] annotations , MediaType mediaType )
{
return
return Serializable . class . isAssignableFrom ( type );
}
public
public boolean
boolean isWriteable ( Class type , Type genericType ,
Annotation [] annotations , MediaType mediaType )
{
return
return Serializable . class . isAssignableFrom ( type );
}
For the isReadable() and isWriteable() methods, we just check to see if our Java type
implements the java.io.Serializable interface:
public
public Object readFrom ( Class type , Type genericType ,
Annotation [] annotations , MediaType mediaType ,
MultivaluedMap httpHeaders ,
InputStream is )
throws
throws IOException , WebApplicationException
{
ObjectInputStream ois = new
new ObjectInputStream ( is );
try
try
{
return
return ois . readObject ();
}
catch
catch ( ClassNotFoundException e )
{
throw
throw new
new RuntimeException ( e );
}
}
The readFrom() method uses basic Java serialization to read a Java object from the HTTP
input stream:
public
public long
long getSize ( Object o , Class type ,
Type genericType , Annotation [] annotations ,
MediaType mediaType )
{
return
return 1 ;
}
The getSize() method returns -1. It is impossible to figure out the exact length of our mar-
shalled Java object without serializing it into a byte buffer and counting the number of bytes.
We're better off letting the servlet container figure this out for us. The getSize() method
has actually been deprecated in JAX-RS 2.0.
Search WWH ::




Custom Search