spring-cloud-openfeign icon indicating copy to clipboard operation
spring-cloud-openfeign copied to clipboard

Support for spring Converter beans for @PathVariables

Open wimdeblauwe opened this issue 5 years ago • 2 comments

I would like to be able to use custom value objects in my feign clients.

For example:

@FeignClient
public interface MyClient {

  @GetMapping("/users/{userId}")
  User getUser(@PathVariable UserId userId);
}

Note how the @PathVariable is typed to UserId, not to String.

I tried adding a org.springframework.core.convert.converter.Converter<UserId,String> in the application context that converts from UserId to String, but that was not used. The toString() method of UserId was still used instead.

wimdeblauwe avatar Feb 11 '21 16:02 wimdeblauwe

You can already archive this by adding to format registrar. @wimdeblauwe

@Bean
FeignFormatterRegistrar feignFormatterRegistrar() {
	return registry -> registry.addConverter(new UserIdConverter());
}

cbezmen avatar May 24 '21 06:05 cbezmen

@OlgaMaciaszek I think you can close this issue?

cbezmen avatar May 26 '21 15:05 cbezmen