twilio SDK内置了jackson,但是我的项目已经有另一个版本的jackson,然后冲突。所以我想让 twilio 使用我的杰克逊。
我试图在 twilio 中排除杰克逊:
<dependency>
<groupId>com.twilio.sdk</groupId>
<artifactId>twilio</artifactId>
<version>10.4.1</version>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</exclusion>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</exclusion>
<exclusion>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-parameter-names</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.14.0</version>
</dependency>
但是当我通过 Feign 将 twilio 的请求结果发送到另一个服务时,出现了问题:
Could not extract response: no suitable HttpMessageConverter found for response type [class com.xxx.SmsSendRespVO] and content type [application/xml;charset=UTF-8]
Twilio.init(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN);
Verification verification = Verification.creator(TWILIO_SERVICE_SID, phoneNumber, "sms")
.setCustomCode(captcha)
.create();
SmsSendRespVO respVO = new SmsSendRespVO();
respVO.setSid(verification.getSid());
respVO.setServiceSid(verification.getServiceSid());
respVO.setAccountSid(verification.getAccountSid());
respVO.setStatus(verification.getStatus());
respVO.setPhoneNumber(phoneNumber);
return respVO;
据我所知,twilio sdk 10.4.1 使用与您在 pom.xml (2.14.0) 中定义的完全相同的 jackson 版本。因此,您不会否决 jackson,而是完全删除所需的 jackson-core 包。 我提出2个选择:
我猜这会起作用
<properties>
<jackson.verison>2.14.0</jackson.version>
</properties>
<dependencies>
<dependency>
<groupId>com.twilio.sdk</groupId>
<artifactId>twilio</artifactId>
<version>10.4.1</version>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</exclusion>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</exclusion>
<exclusion>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-parameter-names</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-parameter-names</artifactId>
<version>${jackson.version}</version>
</dependency>
</dependencies>