OpenFeign / OpenFeign/feign

FieldQueryMapEncoder uses Param.value but ignores Param.expander

Open
#1,312 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

feedback provided proposal
Dominant language
Java
Stars
9.8k
Forks
1.9k
Avg merge
1d 2h
Merged PRs (30d)
41

Description

The FieldQueryMapEncoder implementation uses the Param annotation to set the field names:

https://github.com/OpenFeign/feign/blob/68f79847449c6df36010e9c4118c4244854ea67c/core/src/main/java/feign/querymap/FieldQueryMapEncoder.java#L44-L45

but it does not use its expander to set the value:

https://github.com/OpenFeign/feign/blob/68f79847449c6df36010e9c4118c4244854ea67c/core/src/main/java/feign/querymap/FieldQueryMapEncoder.java#L42-L46

Was this done intentionally or could it be considered a bug?

I was hoping to use the @Param annotation on a POJO of optional query parameters with a field that needs custom encoding, e.g.:

package com.example.opts;

import com.example.expander.CustomExpander;
import feign.Param;
import lombok.Builder;
import lombok.Value;

import java.time.Instant;

@Builder
@Value
public class ExampleOptions {
    @Param(value = "customValue", expander = CustomExpander.class)
    Instant custom;
    Long normal;
}

In this example the parameter is named "customValue", but the value is just the .toString() value of the java.time.Instant instead of the value CustomExpander would have returned.

Please feel free to close this if FieldQueryMapEncoder is meant to work this way. If that's the case, I think it'd make sense to have a custom QueryMapEncoder that uses the expander.

I'd be happy to create a pull request that uses the Param.expander if you think it makes sense.

Thanks,
Shaun

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with core/src/main/java/feign/querymap/FieldQueryMapEncoder.java, especially the handling of Param.value and Param.expander around lines 42-46. Verify how an ExampleOptions field is converted into a query parameter and whether the expander should determine its value. Done means the documented custom expander affects the encoded value while normal fields continue to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.