使用 Apache Camel 将数据库 Table 导出到 JSon 未按预期运行

Export Database Table To JSon Using Apache Camel Not Behaving As Expected

我想使用下面列出的代码使用此代码将数据库的 table 导出到 JSON 文件,代码运行但将返回的数据行拆分为每个记录的文件而不是符合预期的单个文件。

骆驼路线:

 public void configure() throws Exception {
    JsonDataFormat jsonFormat = new JsonDataFormat(JsonLibrary.XStream);
    jsonFormat.setUnmarshalType(Customer.class);
    from("sql: SELECT * FROM assignment01.staff?dataSourceRef=dataSource")
            .marshal(jsonFormat)
            .to("file:data/test");
}

有我的xml

    <bean id="route" class="com.huyqtran.JSonRoute"/>
<camelContext xmlns="http://camel.apache.org/schema/spring">
    <routeBuilder ref="route"/>
</camelContext>
<bean id="dataSource"
      class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
    <property name="url" value="jdbc:mysql://localhost:3306/assignment01?useSSL=false"/>
    <property name="username" value="root"/>
    <property name="password" value=""/>
</bean>

我希望应用程序只为整个 table 创建一个 JSON 文件。

告诉 Camel 使用选项 fileExist=Append 附加到文件:http://camel.apache.org/file2,例如

 .to("file:data/test?fileExist=Append");

或通过转动其迭代器告诉 SQL 组件 return 整个结果集,例如 useIterator=false

   from("sql: SELECT * FROM assignment01.staff?dataSourceRef=dataSource&useIterator=false")