Apache Camel将多个JSON插入CouchDB

问题描述 投票:-1回答:1

我有一些JSON:

json = {"id":"1", "gender":"male", "type":"tes"}

我从Postgresql的select * from mytable获得此JSON,并将该数组转换为json。

我尝试使用template.sendbody("dburl", "json")插入到couchdb

成功,但是当我的数据库中有多个数据时,json看起来像

json = {"id":"1", "gender":"male", "type":"tes"}, {"id":"2", "gender":"male", "type":"tes"}, json = {"id":"3", "gender":"male", "type":"tes"}

错误说

Caused by: org.apache.camel.InvalidPayloadException: No body available of type: java.lang.String but has value: {"id":1,"gender":"male","type":"tes"},{"id":2,"gender":"male","type":"tes"} of type: java.lang.String on: Message[]. Exchange[ID-samsung-PC-1572787069541-0-15]
    at org.apache.camel.component.couchdb.CouchDbProducer.getBodyAsJsonElement(CouchDbProducer.java:88) ~[camel-couchdb-2.24.0.jar:2.24.0]
    at org.apache.camel.component.couchdb.CouchDbProducer.process(CouchDbProducer.java:40) ~[camel-couchdb-2.24.0.jar:2.24.0]
    at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61) ~[camel-core-2.24.0.jar:2.24.0]
    at org.apache.camel.processor.SharedCamelInternalProcessor.process(SharedCamelInternalProcessor.java:186) ~[camel-core-2.24.0.jar:2.24.0]
    at org.apache.camel.processor.SharedCamelInternalProcessor.process(SharedCamelInternalProcessor.java:86) ~[camel-core-2.24.0.jar:2.24.0]
    at org.apache.camel.impl.ProducerCache$1.doInProducer(ProducerCache.java:541) ~[camel-core-2.24.0.jar:2.24.0]
    at org.apache.camel.impl.ProducerCache$1.doInProducer(ProducerCache.java:506) ~[camel-core-2.24.0.jar:2.24.0]
    at org.apache.camel.impl.ProducerCache.doInProducer(ProducerCache.java:369) ~[camel-core-2.24.0.jar:2.24.0]
    at org.apache.camel.impl.ProducerCache.sendExchange(ProducerCache.java:506) ~[camel-core-2.24.0.jar:2.24.0]
    at org.apache.camel.impl.ProducerCache.send(ProducerCache.java:229) ~[camel-core-2.24.0.jar:2.24.0]
    at org.apache.camel.impl.DefaultProducerTemplate.send(DefaultProducerTemplate.java:144) ~[camel-core-2.24.0.jar:2.24.0]
    at org.apache.camel.impl.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:161) ~[camel-core-2.24.0.jar:2.24.0]
    ... 23 common frames omitted

如何在沙发数据库中插入多个json?

json apache-camel couchdb spring-camel
1个回答
0
投票

尝试将您的身体转换为字符串

from("...")
    .convertBodyTo(String.class)
    .to("...");
© www.soinside.com 2019 - 2024. All rights reserved.