Thanks for reporting it, I got it fixed, though if you are still on CXF 2.7.x then you'd need to migrate to 3.0.x or 3.1.x given that 2.7.x is now eol

Sergey
On 04/11/15 15:42, craigrs84 wrote:
Hi.  For JAX-RS web services, I'd like to be able to customize how CXF parses
primitive parameters such as boolean (lowercase).

Whenever I try to use a primitive type with ParamConverterProvider I get an
class cast exception, for example when trying to use with primitive boolean
I receive this exception: "java.lang.ClassCastException: Cannot cast
java.lang.Boolean to boolean".  Looking through the CXF source code, the
problem seems to be occurring in the file InjectionUtils.java, line 388, in
this chunk of code:

        Object result = null;
        try {
            result = createFromParameterHandler(value, pClass, genericType,
paramAnns, message);
        } catch (IllegalArgumentException nfe) {
            throw createParamConversionException(pType, nfe);
        }
        if (result != null) {
*           return pClass.cast(result); //exception is thrown here*
        }

I know I can use uppercase java.lang.Boolean wrapper just fine with
ParamConverterProvider, but I'd like to be able to customize both primitive
boolean and java.lang.Boolean wrapper so that they work consistently.

Some my question is, can the CXF team add support in a future version for
using primitive types with ParamConverterProvider?  Or is this an inherent
limitation of the JAX-RS specification / CXF framework?

Thanks!


Note: here's some sample code snippets of what I'm trying to accomplish:


        public class CustomParamConverterProvider implements 
ParamConverterProvider
        {
                @SuppressWarnings("unchecked")
                @Override
                public <T> ParamConverter<T> getConverter(Class<T> clazz, Type 
type,
Annotation[] annotations)
                {
                        if (clazz.equals(Boolean.class) *|| 
clazz.equals(boolean.class)*)
                                return (ParamConverter<T>)new 
BooleanConverter();
                        return null;
                }
        }

        public static class BooleanConverter implements ParamConverter<Boolean>
        {
                @Override
            public Boolean fromString(String t)
            {
                        if (t == null || t.trim().length() == 0)
                                throw new WebApplicationException(400);
                        
                        try { return new Boolean(t); }
                        catch (Exception ex) { throw new 
WebApplicationException(ex, 400); }
            }

                @Override
                public String toString(Boolean arg0) {
                        return null;
                }
        }






--
View this message in context: 
http://cxf.547215.n5.nabble.com/ParamConverterProvider-use-with-primitive-types-tp5762566.html
Sent from the cxf-user mailing list archive at Nabble.com.



--
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Reply via email to