JSON Encoding - Now in Jersey too


Paul added support for pluggable type system in Jersey. All the supported types need to implement the EntityProvider interface and are registered in the META-INF/services file javax.ws.rs.ext.EntityProvider. Jakub used that system to add support for JSON encoding. Jersey is the GlassFish project that is implementing JAX-RS

The JSON binding in JAX-RS enables to use application/json as the MIME type and specify JSONArray, JSONObject as method parameters and return type. The JSON binding in JAX-RS enables to write code like the following:

public class ExchangeRates {
    public JSONObject getRates() {
        try {
            return new JSONObject()
            .put("USD", 20.04);
        } catch (JSONException ex) {
            throw new WebApplicationException(ex);

JAX-WS takes advantage of a similar pluggable encoding layer in their implementation to provide a JSON binding.


Post a Comment:
Comments are closed for this entry.