users@jersey.java.net

[Jersey] 2 questions

From: Cédric Marcone <cedric.marcone_at_valraiso.fr>
Date: Wed, 29 Dec 2010 15:53:26 +0100

Hello all.

First of all kudos to Jersey developers, to Jax-RS JCP members and to all the JEE6 actors.

You're doing a wonderful job at providing a breakthrough JEE web development platform that finally let us use a modern REST MVC approach without having to resort on using tons of additional libraries.

We are trying hard, as users of the platform, to limit ourselves to only use platform components.

At the Jersey/Jax-RS level, we only have two issues preventing us to get to the web developers heaven :

1) Jersey is a superset of Jax-RS

The full MVC model provided by Jersey (Templates integration using Viewables) is not part of current Jax-RS.
Does anyone know if there is a desire to integrate an similar API at the Jax-RS level for JEE7 ?

2) Mapping of empty strings to non String parameters

As I've read many discussions about it, I know others raised this issue before.
I understand the jersey team position regarding the choices that were made.
I understand the risks of regressions such a change could lead to.
I read somewhere that a global flag could be introduced to change this default behavior.
What is the status of this issue ?

The following example says it all :

---------------------------------------------------------------------------------

import com.sun.jersey.api.view.Viewable;
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

@Path("/test")
@Produces("text/html")
public class Test {

    /**
     * Current recommended way of handling empty non-string parameters
     */
    @POST
    @Path("/asString")
    public Viewable testAsString(@FormParam("value") String value) {
        
        Integer iValue = null;

        if (value != null && !value.isEmpty()) {
            try {
                iValue = Integer.valueOf(value);
            }
            catch (NumberFormatException exception) {}
        }

        return new Viewable("/test.xhtml", iValue);
    }

    /**
     * Produces a status 400, seems more than correct.
     */
    @POST
    @Path("/asInt")
    public Viewable testAsInt(@FormParam("value") int value) {

        return new Viewable("/test.xhtml", value);
    }

    /**
     * Should not produce a status 400, but a null parameter
     */
    @POST
    @Path("/asInteger")
    public Viewable testAsInteger(@FormParam("value") Integer value) {
        
        return new Viewable("/test.xhtml", value);
    }
}

----------------------------------------------------------------------------------

Thank you,
--
Cédric Marcone
Valraiso
France