Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom JAX-RS ParamConverter doesn't work for collection and array types #6761

Closed
sithmein opened this issue Mar 4, 2019 · 4 comments
Closed
Assignees
Labels
in:JAX-RS release bug This bug is present in a released version of Open Liberty release:19003 team:Wendigo West

Comments

@sithmein
Copy link

sithmein commented Mar 4, 2019

I was trying to create a custom javax.ws.rs.ext.ParamConverter<List<String>>. The idea is to convert query parameters such as "ids=i1,i2,i3" into a list of strings i1, i2, i3 in the resource class. The convert is instantiated correctly and used but the call actually fails with

java.lang.ClassCastException: Cannot cast java.util.Arrays$ArrayList to java.lang.String

I did a bit of debugging and it seems there is some special treatment for collections and arrays in org.apache.cxf.jaxrs.utils.InjectionUtils which partially ignores the custom ParamConverter. It's called but the returned value as assume to be the type inside the collection.
Attached is a small example project to reproduce the issue:

  • mvn package
  • java -jar com.knime.enterprise.cloud.service.repository.app/target/cloud.service.repository.app-0.0.2-SNAPSHOT.jar
  • curl http://localhost:9080/repository/foo?ids=1,2,3

The relevant code is in com.knime.enterprise.cloud.service.repository.impl/src/main/java/com/knime/enterprise/cloud/service/repository/impl/v4
This occurs in Open Liberty 18.0.0.3.

jar-zip.zip

@bpaskin-ibm
Copy link

bpaskin-ibm commented Mar 4, 2019

This has nothing to do with the findings of the IBM team, but I believe you need a ? instead of a / after foo to read in the query parameters, which 1,2,3 will be read in as a String first. I do run into the same issue with your sample code.

@WhiteCat22
Copy link
Member

Looks like some of the logic we are doing in InjectionUtils.injectIntoCollectionOrArray() to get the realType could use some work.

paramType=interface java.util.List and genericType=java.util.List<java.lang.String> until that point.

@WhiteCat22
Copy link
Member

I tested with CXF 3.2.8 and the issue does not occur, so this must be the result of some change we've made to CXF.

Uploading the war file (with source) I used to reproduce with vanilla CXF (change .zip to .war)
CXFParamConverter.zip

@andymc12 andymc12 added the release bug This bug is present in a released version of Open Liberty label Mar 18, 2019
@andymc12
Copy link
Contributor

This issue should be resolved in the next Liberty release. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in:JAX-RS release bug This bug is present in a released version of Open Liberty release:19003 team:Wendigo West
Projects
None yet
Development

No branches or pull requests

6 participants