The call between Feign services in SpringCloud mining pit returns xml by default

When I was using SpringCloud a few days ago, I needed to use the call between services, and Feign was used to make the call, but the data in xml format was returned by default.

It mainly introduces the dependency of jackson-dataformat-xml, which provides jackson to convert entity classes into xml-related functions. And jackson itself can convert entity classes into json, so Jackson can convert entity classes into two types of data, and the specific type of data to be converted depends on the accept header information in the http request , the accept of my browser chrome is Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng, / ;q=0.8 Then the server will decide according to accept Whether to return xml or json, because only the last */ of the browser accept matches application/json, and application/xml is in front of /*, the priority is higher than json, so calling directly with the browser will give priority to returning the xml format .

solution:

<dependency>
		<groupId>com.netflix.feign</groupId>
		<artifactId>feign-jackson</artifactId>
		<version>8.18.0</version>
	</dependency>

	<!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
	<dependency>
		<groupId>com.alibaba</groupId>
		<artifactId>fastjson</artifactId>
		<version>1.2.39</version>
	</dependency>

Just import the feign-jackson package

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325646534&siteId=291194637