You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by scardis <sc...@gmail.com> on 2008/04/22 19:43:50 UTC

JAX-RS Boolean Parameter Type

I have a method resembling the following:

@Path("/testBoolean")
@GET
public String getString(@QueryParam("value") Boolean value) {
    if (value != null) {
        return Boolean.toString(value);
    } else {
        return "No value";
    }
}

When I call this service with:
http://localhost:8080/test-rest/test/testBoolean

I receive the String "No Value" as the response (as expected).

However, when calling this service with either of the following two URLS:
http://localhost:8080/test-rest/test/testBoolean?value=true
http://localhost:8080/test-rest/test/testBoolean?value=1

I receive an XMLFault indicating "java.lang.IllegalArgumentException:
argument type mismatch".

What (if any) is the appropriate way (using JAX-RS) to pass a boolean type
argument as a QueryParam?  I realize that I could change the type to String,
but that would dirty my APIs for non-Rest clients.

I can't find anything in the JSR-311 specification, or the CXF documentation
discussing this.

Thanks - 
Steve Ardis

-- 
View this message in context: http://www.nabble.com/JAX-RS-Boolean-Parameter-Type-tp16825382p16825382.html
Sent from the cxf-user mailing list archive at Nabble.com.


RE: JAX-RS Boolean Parameter Type

Posted by "Beryozkin, Sergey" <Se...@iona.com>.
Hi

I've definitely updated the code to convert parameters into objects of
classes which have constructors accepting String or have valueOf(String)
static methods...but the tests were a bit sloppy, so a minor patch have
been attached to ensure the QueryParams are also handled properly...

https://issues.apache.org/jira/browse/CXF-1543


So the code below should work as expected.
In JAX-RS you may also write

public String getString(@DefaultValue("No value") @QueryParam("value")
Boolean value) {
    return Boolean.toString(value);
}

But not in CXF though :-) it could be a nice little patch exercise, if
this feature is needed :-)

Cheers, Sergey

-----Original Message-----
From: scardis [mailto:scardis@gmail.com] 
Sent: 22 April 2008 18:44
To: cxf-user@incubator.apache.org
Subject: JAX-RS Boolean Parameter Type


I have a method resembling the following:

@Path("/testBoolean")
@GET
public String getString(@QueryParam("value") Boolean value) {
    if (value != null) {
        return Boolean.toString(value);
    } else {
        return "No value";
    }
}

When I call this service with:
http://localhost:8080/test-rest/test/testBoolean

I receive the String "No Value" as the response (as expected).

However, when calling this service with either of the following two
URLS:
http://localhost:8080/test-rest/test/testBoolean?value=true
http://localhost:8080/test-rest/test/testBoolean?value=1

I receive an XMLFault indicating "java.lang.IllegalArgumentException:
argument type mismatch".

What (if any) is the appropriate way (using JAX-RS) to pass a boolean
type
argument as a QueryParam?  I realize that I could change the type to
String,
but that would dirty my APIs for non-Rest clients.

I can't find anything in the JSR-311 specification, or the CXF
documentation
discussing this.

Thanks - 
Steve Ardis

-- 
View this message in context:
http://www.nabble.com/JAX-RS-Boolean-Parameter-Type-tp16825382p16825382.
html
Sent from the cxf-user mailing list archive at Nabble.com.

----------------------------
IONA Technologies PLC (registered in Ireland)
Registered Number: 171387
Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland