Hi Brian,

I’ll look into your example.


Weinan Li / JBoss

On May 15, 2014, at 5:34 AM, Brian Mauter <brianmauter@gmail.com> wrote:

Hi, I’d like to accept values other than “true” or “false” for boolean QueryParams (for example, “0” or “1”). It seems that my ParamConverter isn’t being invoked for primitives. I’ve attached a minimal example of what I’m trying to do but some of the most relevant details can be found below.

My TestService method:
@GET
@Produces(MediaType.TEXT_PLAIN)
public String test( @QueryParam("a") boolean a, @QueryParam("b") Boolean b, @QueryParam("c") int c,
@QueryParam("d") Integer d, @QueryParam("e") String e, @QueryParam("f") Date f ) {
return MessageFormat.format( "a={0}, b={1}, c={2}, d={3}, e={4}, f={5}", a, b, c, d, e, f );
}

I invoke it with:
curl -4 -v http://localhost:8080/rt/test?a=1\&b=1\&c=0\&d=0\&e=e\&f=20140514160412-0500

I get back:
a=false, b=true, c=0, d=0, e=e, f=5/14/14 4:04 PM

My two ParamConverters log their arguments in the getConverter, toString and fromString methods. Here’s the log:
2014-05-14 16:22:31,656 http-bio-8080-exec-1 DEBUG [BooleanParamConverter] rawType=class java.lang.Boolean, genericType=class java.lang.Boolean, annotations=[Ljava.lang.annotation.Annotation;@5ae29e22
2014-05-14 16:22:31,657 http-bio-8080-exec-1 DEBUG [BooleanParamConverter] rawType=class java.lang.Integer, genericType=class java.lang.Integer, annotations=[Ljava.lang.annotation.Annotation;@7f42ef92
2014-05-14 16:22:31,657 http-bio-8080-exec-1 DEBUG [DateParamConverter] rawType=class java.lang.Integer, genericType=class java.lang.Integer, annotations=[Ljava.lang.annotation.Annotation;@7f42ef92
2014-05-14 16:22:31,657 http-bio-8080-exec-1 DEBUG [BooleanParamConverter] rawType=class java.lang.String, genericType=class java.lang.String, annotations=[Ljava.lang.annotation.Annotation;@49cd8090
2014-05-14 16:22:31,657 http-bio-8080-exec-1 DEBUG [DateParamConverter] rawType=class java.lang.String, genericType=class java.lang.String, annotations=[Ljava.lang.annotation.Annotation;@49cd8090
2014-05-14 16:22:31,657 http-bio-8080-exec-1 DEBUG [BooleanParamConverter] rawType=class java.util.Date, genericType=class java.util.Date, annotations=[Ljava.lang.annotation.Annotation;@6ff09a85
2014-05-14 16:22:31,657 http-bio-8080-exec-1 DEBUG [DateParamConverter] rawType=class java.util.Date, genericType=class java.util.Date, annotations=[Ljava.lang.annotation.Annotation;@6ff09a85
2014-05-14 16:22:31,684 http-bio-8080-exec-1 DEBUG [BooleanParamConverter] fromString value=1
2014-05-14 16:22:31,684 http-bio-8080-exec-1 DEBUG [DateParamConverter] fromString value=20140514160412-0500

Notice that parameter a in my TestService is a boolean and b is a Boolean. a is never sent to the ParamConverter whereas b is. The same goes for parameters c and d. Is there a rule that says primitives will always use a built-in ParamConverter?

This is Tomcat 7.0.39 and RestEasy 3.0.7.Final.

Thanks,
-Brian

------------------------------------------------------------------------------
"Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
Instantly run your Selenium tests across 300+ browser/OS combos.
Get unparalleled scalability from the best Selenium testing platform available
Simple to use. Nothing to install. Get started now for free."
http://p.sf.net/sfu/SauceLabs

_______________________________________________
Resteasy-developers mailing list
Resteasy-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/resteasy-developers