Conversation
|
Since this changes the return format, I do not want to put this in 5.0.x but it is OK to put in main |
f1b2108 to
0e58e3a
Compare
|
Retargeted to main and rebased onto d4d8148 (0e58e3a). Re-ran on that base: reverting only MatrixVariableParameterProcessor leaves the two added tests failing (SpringMvcContractTests:832 and :840) with the rest of the 71 passing; with the change, |
|
Please sign your commit so the DCO passes |
MatrixVariableParameterProcessor built the path segment from the raw toString() of each value, so a collection came out bracketed: ;colours=[red, blue] instead of ;colours=red,blue. A matrix variable separates repeated values with a comma, so the receiving side reads "[red" and " blue]" back out of the bracketed form. Both branches of the processor were affected, including the Map<String, List<String>> signature used as the @MatrixVariable example in the reference documentation. Signed-off-by: kdelay <kdelay20@gmail.com>
0e58e3a to
bd2b41f
Compare
| assertThat(";param=value").isEqualTo(data.indexToExpander().get(0).expand(testMap)); | ||
| } | ||
|
|
||
| @Test |
There was a problem hiding this comment.
Can we add a test through a real Feign client and/or RestTemplate? I believe RequestTemplateFactoryResolver.expandElements() will add a , in the result as well
|
|
||
| private String expandValue(Object value) { | ||
| if (value instanceof Collection<?> values) { | ||
| return values.stream().filter(Objects::nonNull).map(Object::toString).collect(Collectors.joining(",")); |
There was a problem hiding this comment.
I think you can use org.springframework.util.StringUtils.collectionToCommaDelimitedString
Use StringUtils.collectionToCommaDelimitedString for the join and flatten arrays and nested collections through the same path. Signed-off-by: kdelay <kdelay20@gmail.com>
|
Done in 4bb1784: join via You are right about |
No, IMO we should deal with it as part of this change |
Feign pct-encodes every value it substitutes into a URI template, so the ';' and '=' produced by the expander left the segment as %3Bname%3Dvalue and the server could not read it as matrix variables. Move the ';name=' prefix into the URI template, where it survives as a literal, and let the expander produce only the value. A collection parameter is expanded element by element by Feign and joined with ',', which now yields ';colours=red,blue'. Signed-off-by: kdelay <kdelay20@gmail.com>
|
Done in 02fbad7. Feign pct-encodes every value substituted into a URI template, so the separators came out as Measured through a stub Arrays (not
|
| } | ||
|
|
||
| private String expandValue(Object value) { | ||
| if (value.getClass().isArray()) { |
There was a problem hiding this comment.
I don't think the Map-typed @MatrixVariable case case is handled properly
Let Feign expand a Map typed matrix variable through a path-style URI template expression, so the ; and = separators stay literal in the request URL and only the keys and the values are encoded. Signed-off-by: kdelay <kdelay20@gmail.com>
|
Done in 94a9ad3: the Collection-valued entries are still not covered: |
MatrixVariableParameterProcessorbuilds the path segment from each value'stoString(), so a collection value comes out bracketed.For
@MatrixVariable Map<String, List<String>> matrixVars(the signature used as the example in the reference docs) withcolours=[red, blue]andsize=L, it produces;colours=[red, blue];size=L. A matrix variable separates repeated values with a comma, soWebUtils.parseMatrixVariables(Spring 7.1.0-SNAPSHOT) reads that back as{colours=[[red, blue]], size=[L]}. With;colours=red,blue;size=Lit reads{colours=[red, blue], size=[L]}.The single-object branch had the same problem, so
@MatrixVariable("colours") List<String>is covered too../mvnw -P spring -pl spring-cloud-openfeign-core verify: 445 tests, 0 failures. Both added tests fail onmainwithout the change.