【发布时间】:2020-07-21 06:23:50
【问题描述】:
最近将我的项目从 2.1.X
更新为 Spring boot 到 2.2.X更新项目后遇到异常。
我正在使用 spring 提供的 JSON 转换器将 json 字符串转换为对象。
myproject-context.xml
<int-amqp:inbound-channel-adapter id="updateProductDetailsQueueAdapter"
channel="updateProductDetailsQueueChannel" queue-names="update-product-details-queue"
connection-factory="rabbitConnectionFactory"/>
<int:json-to-object-transformer
input-channel="updateProductDetailsQueueChannel"
output-channel="updateProductDetailsTransformerInputChannel" type="org.somePackage.UpdateProductDetailsEvent" />
<int:transformer
input-channel="updateProductDetailsTransformerInputChannel"
output-channel="updateProductDetailsTransformerOutputChannel" expression="payload.getUpdateMessage()" />
模型类
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
@Getter
@ToString
@EqualsAndHashCode
public class UpdateProductDetailsEvent implements Serializable {
private static final long serialVersionUID = 1L;
private String productType;
private String updateMessage;
@JsonCreator
public UpdateProductDetailsEvent(@JsonProperty("productType") String productType, @JsonProperty("updateMessage") String updateMessage) {
this.productType = productType;
this.updateMessage = updateMessage;
}
}
Caused by:
org.springframework.integration.transformer.MessageTransformationException: failed to
transform message; nested exception is java.io.UncheckedIOException:
com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of
`java.lang.String` out of START_OBJECT token
at [Source: (String)"{"productType":"Electronics","updateMessage":"Description to update"}"; line: 1, column: 1]
.........................
.........................
Caused by:
java.io.UncheckedIOException:
com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of
`java.lang.String` out of START_OBJECT token
at [Source: (String)"{"productType":"Electronics","updateMessage":"Description to update"}"; line: 1, column: 1] at
org.springframework.integration.json.JsonToObjectTransformer.doTransform
(JsonToObjectTransformer.java:132) ~[spring-integration-core-5.2.1.RELEASE.jar:5.2.1.RELEASE]
【问题讨论】:
-
有没有机会和我们分享一个简单的 Spring Boot 项目来重现和使用?
标签: java spring-boot spring-integration spring-amqp