Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Parsing enumeration parameters through Spring Boot and dummy client
Parsing enumeration parameters through Spring Boot and dummy client
Enumeration parsing in SpringBoot uses EnumToStringConverter by default, and is converted to the name of enumeration by default.

In response to JSON return, Enum also resolves to name by default.

Sometimes, this value is not an enumeration name, but is used for return and parameter resolution.

Submitting gender= 1 at this time will fail to parse, which can be achieved by configuring MessageConvertFactory.

Define StringToEnumConverterFactory:

Configure mvc

Call access at this time, and Feign will change the gender into a name to access? Gender = male, in this case, the server must report an error because our Enum resolution is no longer name.

Therefore, it is necessary to configure FeignClient to support Enum to be converted into the value marked by JsonValue for access.

Define converter:

Configure FeignClient:

Through the above three steps, the request and response of Enum parameters can be realized.