Class HtmlJsonProvider

  • All Implemented Interfaces:
    jakarta.ws.rs.ext.MessageBodyReader<Object>, jakarta.ws.rs.ext.MessageBodyWriter<Object>

    public final class HtmlJsonProvider
    extends Object
    implements jakarta.ws.rs.ext.MessageBodyWriter<Object>, jakarta.ws.rs.ext.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() {
         WebTarget target = ...;
         Query q = target.request(MediaType.APPLICATION_JSON).get().readEntity(Query.class);
         return q.getItems();
       }
     }
     
    Author:
    Jaroslav Tulach (jtulach at netbeans.org)
    • Constructor Detail

      • HtmlJsonProvider

        public HtmlJsonProvider()
    • Method Detail

      • isWriteable

        public boolean isWriteable​(Class clazz,
                                   Type type,
                                   Annotation[] antns,
                                   jakarta.ws.rs.core.MediaType mt)
        Specified by:
        isWriteable in interface jakarta.ws.rs.ext.MessageBodyWriter<Object>
      • getSize

        public long getSize​(Object t,
                            Class type,
                            Type type1,
                            Annotation[] antns,
                            jakarta.ws.rs.core.MediaType mt)
        Specified by:
        getSize in interface jakarta.ws.rs.ext.MessageBodyWriter<Object>
      • writeTo

        public void writeTo​(Object t,
                            Class type,
                            Type type1,
                            Annotation[] antns,
                            jakarta.ws.rs.core.MediaType mt,
                            jakarta.ws.rs.core.MultivaluedMap mm,
                            OutputStream out)
                     throws IOException,
                            jakarta.ws.rs.WebApplicationException
        Specified by:
        writeTo in interface jakarta.ws.rs.ext.MessageBodyWriter<Object>
        Throws:
        IOException
        jakarta.ws.rs.WebApplicationException
      • isReadable

        public boolean isReadable​(Class<?> type,
                                  Type type1,
                                  Annotation[] antns,
                                  jakarta.ws.rs.core.MediaType mt)
        Specified by:
        isReadable in interface jakarta.ws.rs.ext.MessageBodyReader<Object>