feign icon indicating copy to clipboard operation
feign copied to clipboard

feign not support null value param of http Get method

Open xinluke opened this issue 9 years ago • 4 comments

hi,i have one questtion in server,define a controller

@RequestMapping(value = "/helloWorld", method = RequestMethod.GET)
    public void helloWorld(@RequestParam("isEnable") Integer isEnable) {
        log.info("status:{}",isEnable);
    }

in client,define feign interface

@RequestMapping(value = "/helloWorld", method = RequestMethod.GET)
    public void helloWorld(@RequestParam("isEnable") Integer isEnable) ;
 

if like this,server will log status:1

feignClient.helloWorld(1)

watch request is :http://127.0.0.1:8080/helloWorld?isEnable=1 but, if set isEnable=null,feign would ignore isEnable query param field,so server would not support that. now, i watch that the request is :http://127.0.0.1:8080/helloWorld i think, feign request should be,http://127.0.0.1:8080/helloWorld?isEnable=,and i use curl test ,server can be normal deal with

xinluke avatar Jul 13 '17 06:07 xinluke

The example is from code not in this repo. However, I think it is generally true. There is no flag to retain a key on null. Ex to acheive what you want you would have to pass "" or overload the method without the parameter.

If this was a popular request other things like extending the annotation might be possible

On 13 Jul 2017 2:50 pm, "xinluke" [email protected] wrote:

hi,i have one questtion in server,define a controller ‘’’ @requestmapping(value = "/helloWorld", method = RequestMethod.GET) public void helloWorld(@requestparam("isEnable") Integer isEnable) { log.info("status:{}",isEnable); } ‘’‘ in client,define feign interface ‘’’ @requestmapping(value = "/helloWorld", method = RequestMethod.GET) public void helloWorld(@requestparam("isEnable") Integer isEnable) ;

‘’‘ if like this,server will log status:1

feignClient.helloWorld(1)

watch request is :http://127.0.0.1:8080/helloWorld?isEnable=1 but, if set isEnable=null,feign would ignore isEnable query param field,so server would not support that. now, the request is :http://127.0.0.1:8080/helloWorld i think, feign request should be,http://127.0.0.1:8080/ helloWorld?isEnable=,and i use curl test ,server can be normal deal with

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/OpenFeign/feign/issues/575, or mute the thread https://github.com/notifications/unsubscribe-auth/AAD611sOBq--co4RRUEFqO5_3ULLdqU5ks5sNb4fgaJpZM4OWkl1 .

codefromthecrypt avatar Jul 14 '17 01:07 codefromthecrypt

If feign ignore that null value ,parameter name from get request URI , then how it would be possible to build such URI from springs org.springframework.web.util.UriComponentsBuilder.class.

(I'm wondering how to migrate from org.springframework.cloud.netflix.feign.FeignClient.class to org.springframework.web.reactive.function.client.WebClient.class )

How to do that without using string concatenation like below(focus on query part):

public Mono<ResourceCentersDto> findAllResourceCenters(String userId) {
    return webClient
        .get()
        .uri(
            uriBuilder ->
                uriBuilder
                    .scheme(HTTP)
                    .host("{service-name}")
                    .path("api/resource-centers")
                    .query(StringUtils.isEmpty(userId) ? userId : "userId=" + userId)
                    .build(SERVICE_NAME))
        .accept(MediaType.APPLICATION_JSON)
        .retrieve()
        .bodyToMono(ResourceCentersDto.class)
        .retry(maxRetries)
        .doOnError(e -> LOGGER.error("Error on finding resource centers for user [{}]", userId, e));

walakulu avatar Oct 30 '19 06:10 walakulu

Hi I am also facing same issue as #xinluke. Can this issue reopen. In My project I am using feign only So, I don't have other choice.

subhamoy024 avatar May 24 '21 20:05 subhamoy024

Hi I am also facing same issue as #xinluke. Can this issue reopen. In My project I am using feign only So, I don't have other choice.

you can have a second method w/o the parameter.

for feign dealing with nulls would be tricky...

some people will ask for null to remove that parameter (?), other people will ask to send null (?userId=null) and other people will ask to send nothing (?userId)...

Better have two methods and deal with your favorite behavior on your code

velo avatar May 24 '21 20:05 velo