Reusing existing XmlAdapters makes sense to me, so I updated the trunk/2.3.x
for adapters be checked when processing all types of JAX-RS parameters

Give it a try please with the latest code

It doesnt work, I will explain what happens in the current code:

I have a method annotated this way:

void methodA( @PathParam("id") @XmlJavaTypeAdapter(ValueTypeToBoundTypeAdapter.class) param1);

So actually InjectionUtils.handleParameter() now tries to convert a String from the URI in the following way:

it searches for "fromString", "fromValue", .. in type BoundType (which is the pClass parameter). This will fail (result=null) and then it tries to convert the String to BoundType using JAXBUtils.convertWithAdapter(), which will use ValueTypeToBoundTypeAdapter. However ValueTypeToBoundTypeAdapter can only convert ValueType to BoundType, and ValueType is no String, but has a fromString() method.

So what should happen (at least what I expect), is that ValueType.fromString(String) called and the resulting ValueType is converted using ValueTypeToBoundTypeAdapter to a BoundType.

The following code would fix it:

Replace

        // check constructors accepting a single String value

by

        // convert from BoundType to ValueType if adapter is present
        pClass = getActualType(pClass, pClass, paramAnns);
        // check constructors accepting a single String value


and replace


        if (result == null) {
            // as the last resort, try XmlJavaTypeAdapters
            try {
                result = JAXBUtils.convertWithAdapter(value, paramAnns);
            } catch (Throwable ex) {
// ignore - may be to do with JAXB classes not being available
            }
        }

by

                // apply XmlJavaTypeAdapters if present
                try {
result = JAXBUtils.useAdapter(result != null ? result : value, AnnotationUtils.getAnnotation(paramAnns, XmlJavaTypeAdapter.class), false, result);
                } catch (Throwable ex) {
// ignore - may be to do with JAXB classes not being available
                }



I also copied getActualType(.,.,.) and getAdapter(.,.) from AbstractJAXBProvider. With this fix, all my tests work.

Reply via email to