Class HtmlJsonProvider
java.lang.Object
org.glassfish.jersey.media.htmljson.HtmlJsonProvider
- All Implemented Interfaces:
MessageBodyReader<Object>,MessageBodyWriter<Object>
public final class HtmlJsonProvider
extends Object
implements MessageBodyWriter<Object>, MessageBodyReader<Object>
Implementation of Jersey's message body reader and writer that
can handle reading and writing of JSON models generated by
Model
annotation provided by
net.java.html.json
library. Include
this JAR in your project and you can then use your
model classes as Jersey's entities.
@Model(className="Query", properties={@Property(name="items", type=Item.class, array=true) }) class QueryImpl {@Model(className="Item", properties={@Property(name="id", type=String.class),@Property(name="kind", type=Kind.class) }) class ItemImpl { } enum Kind { GOOD, BAD } public static List<Item>doQuery() {WebTargettarget = ...; Query q = target.request(MediaType.APPLICATION_JSON).get().readEntity(Query.class); return q.getItems(); } }
- Author:
- Jaroslav Tulach (jtulach at netbeans.org)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlongbooleanisReadable(Class<?> type, Type type1, Annotation[] antns, MediaType mt) booleanisWriteable(Class clazz, Type type, Annotation[] antns, MediaType mt) readFrom(Class<Object> clazz, Type type, Annotation[] antns, MediaType mt, MultivaluedMap<String, String> mm, InputStream in) voidwriteTo(Object t, Class type, Type type1, Annotation[] antns, MediaType mt, MultivaluedMap mm, OutputStream out)
-
Constructor Details
-
HtmlJsonProvider
public HtmlJsonProvider()
-
-
Method Details
-
isWriteable
- Specified by:
isWriteablein interfaceMessageBodyWriter<Object>
-
getSize
- Specified by:
getSizein interfaceMessageBodyWriter<Object>
-
writeTo
public void writeTo(Object t, Class type, Type type1, Annotation[] antns, MediaType mt, MultivaluedMap mm, OutputStream out) throws IOException, WebApplicationException - Specified by:
writeToin interfaceMessageBodyWriter<Object>- Throws:
IOExceptionWebApplicationException
-
isReadable
- Specified by:
isReadablein interfaceMessageBodyReader<Object>
-
readFrom
public Object readFrom(Class<Object> clazz, Type type, Annotation[] antns, MediaType mt, MultivaluedMap<String, String> mm, InputStream in) throws IOException, WebApplicationException- Specified by:
readFromin interfaceMessageBodyReader<Object>- Throws:
IOExceptionWebApplicationException
-