Body parameters cannot be used with form parameters – Feign client with Headers and json data


I have a FeignClient like this

@RequestLine("POST /enroll")
@Headers({ "header1: {header1}", "header2: {header2}", "Content-Type: application/json" })
ResponseDto enroll(@Param("header1") String header1,@Param("header1") String header1, RequestDto requestDto)throws MyCustomException;

I am not using spring cloud netflix. But I am keep getting the below exception.

Caused by: java.lang.IllegalStateException: Body parameters cannot be used with form parameters.
at feign.Util.checkState(
at feign.Contract$BaseContract.parseAndValidateMetadata(
at feign.Contract$BaseContract.parseAndValidatateMetadata(
at feign.ReflectiveFeign$ParseHandlersByName.apply(
at feign.ReflectiveFeign.newInstance(
at feign.Feign$
at feign.Feign$

I am instantiating my client like this.

return Feign.builder()
        .encoder(new JacksonEncoder())
        .decoder(new JacksonDecoder())
        .logger(new Slf4jLogger())
        .target(RegularFeignClient.class, url);


Wow this a tricky one. The order of parameters matter here.

@RequestLine("POST /enroll")
@Headers({ "header1: {header1}", "header2: {header2}", "Content-Type: application/json" })
ResponseDto enroll(RequestDto requestDto, @Param("header1") String header1,@Param("header1") String header1)throws MyCustomException;

This works!!!

Thanks to my senior developer. He found it.

Answered By – Seetharamani Tmr

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published