cxf-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Diego Ruotolo <diego.ruot...@gmail.com>
Subject ParamCoverter, List, CSV query parameters
Date Sun, 16 Oct 2016 22:48:34 GMT
Hi everybody,

this is my first post to this mailing list.
I am using Apache CXF and I have the following problem: I need to read a 
multiple-value query parameter that is written in a 
comma-separated-values (CSV) format, hence non standard HTTP way.
I know that this will be fixed in versions 3.1.8 and 3.2.0 with the 
contextual property "parse.query.value.as.collection", as written here:
https://issues.apache.org/jira/browse/CXF-6941
but the above solution works for ALL query parameters, I want to be 
selective, for instance I just want query parameters annotated with 
@MyAnnotation to be parsed as CSV collection, other query parameters may 
accept commas as a value.
Therefore I've written a ParamConverter provided by a 
ParamConverterProvider: the latter reads the annotation and returns the 
appriopriate ParamConverter that converts a String into a List. But this 
is not working since the returned List is used as first element of the 
linked method parameter, so in the end I have a List of List.

Example:

Query parameter: MY_PARAM=VALUE_1,VALUE_2,VALUE_3
Method parameter: List<?> myParam; // Here I put "?" instead of "String" 
as generic type in order to explain this example
ParamConverter fromString() method: return 
Arrays.asList(value.split(",")); //returns a List<String>
Expected result: myParam is a List<String>, a list of 3 elements 
(VALUE_1, VALUE_2, VALUE_3)
Actual result: myParam is a List<List<String>>, a list with one element, 
this single element is a list of 3 elements (VALUE_1, VALUE_2, VALUE_3)

It seems that when used in conjuction with a List (a Collection?) method 
parameter, a ParamConverter works per-element, not for the whole list.
Is this the correct behaviour? Do you know some work-around that I could 
use without writing an Apache CXF Interceptor (I don't want to be bound 
to an implementation of JAX-RS) ?
I've noticed that Jersey has a similar issue too: 
https://java.net/jira/browse/JERSEY-2763

Thanks in advice,

best regards
-- 
*Eng. Diego Ruotolo*

diego.ruotolo@gmail.com <mailto:diego.ruotolo@gmail.com>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message