Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

Hi Bryant please disregard the information located below, unless it is relevant, it just a collection of things that I thought was relevant.

...

JSON Providers

Apache Wink provides a set of providers that are capable of serializing a number of data models (JSONObject, JAXBElement, SyndEntry, SyndFeed) into JSON representations. There are currently three Apache Wink extensions that provide JSON support. The following tables list these providers.

JsonProvider

Each has unique features that may make one more suitable for your particular application.

wink-json-provider (org.json)

The wink-json-provider extension is provided in the binary distribution and uses the JSON.org classes to provide JSON support. Include the wink-json-provider-<VERSION>.jar in the classpath and the providers will automatically be registered. You will also need the org.json JAR which is provided in the ext/wink-json-provider/lib folder.

org.apache.wink.providers.json.JsonProvider

Handles reading and writing of org.json.JSONObject classes for the application/json and application/javascript media types.TBD

 

Supported

Media Types

Entity

Read

Yes

application/json , application/javascript

org.json.JSONObject

Write

Yes

application/json , application/javascript

org.json.JSONObject

org.apache.wink.providers.json.JsonArrayProvider

Handles reading and writing of org.json.JSONArray classes for the application/json and application/javascript media types.

 

Supported

Media Types

Entity

Read

Yes

application/json , application/javascript

org.json.JSONArray

No

N/A

N/A

Write

Yes

application/json , application/javascript

JSONObject >>

JsonJAXBProvider

org.json.JSONArray

org.apache.wink.providers.json.JsonJAXBProvider

Handles reading and writing of JAXBElement and JAXB annotated classes for the application/json and application/javascript media types.TBD

 

Supported

Media Types

Entity

Read

No

N/A

Yes

application/json , application/javascript

JAXB object,
JAXBElement<?>>> N/A

Write

Yes

application/json , application/javascript

JAXB object,
JAXBElement<?>>>

JsonSyndEntryProvider

Producing and Consuming JSON Example

The following example demonstrates the usage of a JSON provider for reading and writing JSON representations.

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;
    }

wink-jettison-provider (org.codehaus.jettison)

The wink-jettison-provider extension is provided in the binary distribution and uses the Jettison code to provide JSON support. Include the wink-jettison-provider-<VERSION>.jar in the classpath and the providers will automatically be registered. You will also need the Jettison library JARs which are provided in the ext/wink-jettison-provider/lib folder.

By default, reading is currently disabled due to potential issues with the reader. You can enable it by calling setUseAsReader(boolean) on each provider and registering as a singleton in the JAX-RS Application sub-class.

org.apache.wink.providers.jettison.JettisonJAXBElementProvider

Handles reading and writing of JAXBElement classes for the application/json media type.TBD

 

Supported

Media Types

Entity

Read

Yes No

N application/A
N/A json

JAXBElement<?>>>

Write

Yes

application/json , application/javascript

SyndEntry>>

JsonSyndFeedProvider


JAXBElement<?>>>

org.apache.wink.providers.jettison.JettisonJAXBElementProvider

Handles reading and writing of JAXB annotated classes for the application/json media type.TBD

 

Supported

Media Types

Entity

Read

Yes No

N application/A
N/A json

JAXB object

Write

Yes

application/json , application/javascript

SyndFeed>>

JSON Data Models


JAXB object

Example

The following examples demonstrates the usage of a Jettison provider for producing and consuming JSON.

Jettison Provider Registration

The following code example demonstrates the way to register a Jettison provider within a JAX-RS application.

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

The following code example demonstrates the reading and writting of JAXB objects into a JSON representation by using a Jettison provider.

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;
    }

Jackson JSON Processor

Jackson JSON Processor may also suit your needs and can be used. They provide their own JAX-RS entity provider. See their documentation for more informationApache Wink provides a JSON data model for producing JSON (application/json). All of the model classes are located under the com.hp.Apache Wink.common.model.json package.