Bagbyte
Bagbyte

Reputation: 863

Java + Jersey server start error

I'm getting this error when trying to start my server:

Error processing resource method, public java.lang.String com.restful.res.UsersWS.getUsersLists(java.lang.Long,java.lang.Boolean,java.lang.Integer,java.lang.Boolean,java.lang.Integer,java.lang.Boolean,java.lang.Integer,java.lang.Boolean,java.lang.Integer,java.lang.Double,java.lang.Double) throws org.codehaus.jettison.json.JSONException, for ResourceMethodDispatchProvider, com.sun.jersey.server.impl.model.method.dispatch.EntityParamDispatchProvider.
com.sun.jersey.api.container.ContainerException: Could not process parameter type class java.lang.Double

here my code:

@GET
//  @Path("/{userId}/users")
    public String getUsersLists(@QueryParam("userId") Long userId,
//          @PathParam("userId") Long userId,
            @DefaultValue("true") @QueryParam("near") Boolean near,
            @DefaultValue("0") @QueryParam("nearLimit") Integer nearLimit,
            @DefaultValue("true") @QueryParam("pref") Boolean pref,
            @DefaultValue("0") @QueryParam("prefLimit") Integer prefLimit,
            @DefaultValue("false") @QueryParam("fb") Boolean fb,
            @DefaultValue("0") @QueryParam("fbLimit") Integer fbLimit,
            @DefaultValue("false") @QueryParam("adBook") Boolean adBook,
            @DefaultValue("0") @QueryParam("adBookLimit") Integer adBookLimit,
            @DefaultValue("null") @QueryParam("lat") Double lat,
            @DefaultValue("null") @QueryParam("lon") Double lon) throws JSONException {

Upvotes: 0

Views: 1496

Answers (1)

Brian Roach
Brian Roach

Reputation: 76888

The @DefaultValue annotation uses the type's constructor that takes a single String argument.

Pulling up the source code for jersey, it checks the default values for validity at runtime which is why you're getting an exception; "null" isn't a valid number for a Double and an attempt to pass that to the constructor results in a NumberFormatException which jersery then wraps in its own exception and rethrows.

Looking at the Javadoc for Double, about the closest thing I could suggest is perhaps using "NaN" (Not a Number) and then checking for that in your code. Of course, since you're talking about latitude and longitude, perhaps just using "0.0" would be fine?

Edit to add: As noted in the comments to your question, option B which is probably a more sound approach all around would be to switch to POST and send JSON to your REST call, deserializing it to a POJO and going from there.

Upvotes: 3

Related Questions