Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

 

Supported

Media Types

Entity

Read

Yes

application/json , application/javascript

JAXB object,
JAXBElement<?>>>

Write

Yes

application/json , application/javascript

JAXB object,
JAXBElement<?>>>

Examples

TBD

Producing and Consuming JSON

TBD

Code Block
    @GET
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    public JSONObject postJSON(JSONObject requestJSON) {
        String property = requestJSON.getString("property");
        JSONObject jobj = new JSONObject();
        return jobj;
    }

    /* Book is a JAXB annotated class */

    @GET
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    public Book postJSONBook(Book requestBookEntity) {
        String title = requestBookEntity.getTitle();
        /* other code */
        Book response = new Book();
        return response;
    }

...

 

Supported

Media Types

Entity

Read

Yes

application/json

JAXB object

Write

Yes

application/json

JAXB object

Example

TBD

Enabling Reading

TBD

Code Block
    public class MyApp extends Application {
        public Set getClasses() {
            Set s = new HashSet();
            s.add(MyResource.class);
            return s;
        }

        public Set<Object> getSingletons() {
            Set s = new HashSet();
            JettisonJAXBProvider jaxbProvider = new JettisonJAXBProvider();
            jaxbProvider.setUseAsReader(true);
            return s;
        }
    }

Producing and Consuming JSON

TBD

Code Block
    /* Book is a JAXB annotated class */

    @GET
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    public Book postJSONBook(Book requestBookEntity) {
        String title = requestBookEntity.getTitle();
        /* other code */
        Book response = new Book();
        return response;
    }

...