【发布时间】:2015-01-15 11:29:21
【问题描述】:
我们收到以下错误:
org.springframework.web.client.RestClientException: Could not write request:
no suitable HttpMessageConverter found for
request type [com.company.FileRecord] and
content type [application/x-java-serialized-object]
at org.springframework.web.client.RestTemplate$HttpEntityRequestCallback.doWithRequest(RestTemplate.java:770)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:549)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:527)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:472)
...
这是由带有MappingJackson2HttpMessageConverter 的http:outbound-gateway 抛出的,如下所示:
<bean id="jsonMessageConverter"
class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="supportedMediaTypes"
value="application/x-java-serialized-object"/>
</bean>
<int:transformer input-channel="transformationChannel"
output-channel="registrationQueue"
ref="fileTransformer"/>
<int:channel id="registrationQueue"/>
<int-http:outbound-gateway id="gateway"
request-channel="registrationQueue"
message-converters="jsonMessageConverter"
url-expression="@urlGenerator.resolve()"
http-method="POST"
expected-response-type="javax.ws.rs.core.Response"
reply-channel="nullChannel"
error-handler="httpResponseErrorHandler"/>
被序列化的 Out 对象为 Jackson 序列化注解:
public class FileRecord {
@JsonProperty
private final String id;
@JsonProperty
private final String path;
...
}
我相信这是与 Spring Integration 2.2 一起使用的,但在迁移到 3.0 时开始失败。
奇怪的是,我们试图将其序列化为application/x-java-serialized-object。我希望application/json 在这里。也许需要header-enricher?如果是这样,我想了解为什么需要表达这一点。我的jsonMessageConverter不应该知道吗?
【问题讨论】:
标签: java json spring serialization spring-integration