Skip to content

Apply @Param expanders on QueryMap POJO fields and getters - #3658

Open
havefunatcode wants to merge 1 commit into
OpenFeign:masterfrom
havefunatcode:querymap-param-expander
Open

havefunatcode wants to merge 1 commit into
OpenFeign:masterfrom
havefunatcode:querymap-param-expander

Conversation

@havefunatcode

Copy link
Copy Markdown

FieldQueryMapEncoder and BeanQueryMapEncoder only used @Param on a @QueryMap POJO for the name, so expander was ignored:

@Param(value = "since", expander = DateToMillis.class)
private final Date since; // sent as Date.toString()

Both encoders now create the expander once per class, next to the existing metadata cache, and apply it in encode. It's instantiated with newInstance() like method params are, and a failure throws EncodeException. An Iterable is expanded per element (null elements stay null), anything else (arrays too) goes to the expander as a whole, same as a method @Param. If the expander returns null the entry is dropped like a null field.

Also fixed @Param(expander = Foo.class) with no value, which sent the param with an empty name. It falls back to the field/property name now.

@HeaderMap POJOs use the same encoder, so header fields get their expanders too. Header POJOs without an expander are unchanged. Happy to limit it to query maps if you'd prefer.

Added defaultEncoder_withParamExpander to both encoder tests (they fail on master) and mvn -pl core test passes. README and CHANGELOG updated.

Fixes #1312

FieldQueryMapEncoder and BeanQueryMapEncoder now apply the @PARAM
expander, per element for an Iterable. A @PARAM without a value falls
back to the field or property name. @HeaderMap POJOs go through the
same encoders, so their expanders apply too.

Fixes OpenFeign#1312
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FieldQueryMapEncoder uses Param.value but ignores Param.expander

1 participant