【问题标题】:Apache camel cannot marshal to JSON from InputStreamCacheApache camel 无法从 InputStreamCache 编组为 JSON
【发布时间】:2017-04-02 02:56:30
【问题描述】:

在 Apache Camel 中,我公开了一个 REST 服务,将其输入用于调用 SOAP 服务,然后我想将 SOAP 响应编组为 JSON。我的 RouteBuilder 大致如下:

rest("/api")
 .get("/client/{id}")
 .to("direct:getClient");

from("direct:getClient")
 .log(LoggingLevel.INFO, "Getting client with id ${id}")
 .process(new GetClientProcessor())
 .marshal().jaxb()
 .to("spring-ws:http://localhost:9000/searchClient?soapAction=search")
 .process(new ClientProcessor())
 .marshal().json(JsonLibrary.Jackson);

在将结果编组为 JSON 时出现以下错误:

com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class org.apache.camel.converter.stream.InputStreamCache and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS)
    at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:275)
    at com.fasterxml.jackson.databind.SerializerProvider.mappingException(SerializerProvider.java:1110)
    at com.fasterxml.jackson.databind.SerializerProvider.reportMappingProblem(SerializerProvider.java:1135)
    at com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.failForEmpty(UnknownSerializer.java:69)
    at com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.serialize(UnknownSerializer.java:32)
    at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:292)
    ...

我知道为什么会这样,因为我默认开启了流缓存。但是,我不知道如何在不关闭流缓存的情况下解决此问题。

我已经搜索过 Camel 文档、邮件列表和论坛,但目前还没有找到有用的信息。

【问题讨论】:

标签: java json jackson apache-camel marshalling


【解决方案1】:

我终于解决了。该问题与描述的路线无关,而是与全局休息配置有关:

RestConfiguration restConfiguration = new RestConfiguration();
restConfiguration.setComponent("servlet");
restConfiguration.setBindingMode(RestConfiguration.RestBindingMode.json);
restConfiguration.setHost("localhost");
restConfiguration.setPort(serverPort);

camelContext.setRestConfiguration(restConfiguration);

第三行,设置绑定模式,是不必要的,因为我明确指出当我想映射到 JSON 以及我使用哪个框架时。删除这条线后,一切都像魅力一样。

目前我不完全知道这如何或为什么解决了我的问题,但我很高兴它解决了;)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-31
    相关资源
    最近更新 更多