我对 BeanIO 的 recordTerminator 解析器属性感兴趣。它是否也适用于细分,例如“segmentTerminator”?即,我有一个固定长度格式的流,包含一条带有可重复段的记录,并且所有流都是一行。因此,我设置了 recordTerminator="",但它仍然给了我
==> Invalid 'state': Expected minimum 1 occurrences
==> Invalid 'city': Expected minimum 1 occurrences
==> Invalid 'street': Invalid field length, expected 35 characters
==> Invalid 'zip': Expected minimum 1 occurrences
它不会抱怨可重复段之前的字段,并且对可重复段中的字段的抱怨是在 mapping.xml 中定义的乱序,如下所示:
<beanio xmlns="http://www.beanio.org/2012/03" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.beanio.org/2012/03 http://www.beanio.org/2012/03/mapping.xsd">
<stream name="employeeFile" format="fixedlength">
<parser>
<property name="recordTerminator" value="" />
</parser>
<record name="employee" class="example.Employee">
<field name="firstName" length="35" />
<field name="lastName" length="35" />
<field name="title" length="35" />
<field name="salary" length="35" />
<segment name="addressList" collection="list" minOccurs="1" maxOccurs="unbounded" class="example.Address">
<field name="street" length="35" />
<field name="city" length="35" />
<field name="state" length="35" />
<field name="zip" length="10" />
</segment>
</record>
</stream>
</beanio>
类实现是这样的:
package example;
public class Employee {
String firstName;
String lastName;
String title;
String salary;
List<Address> addressList;
// getters and setters not shown...
}
package example;
public class Address {
private String street;
private String city;
private String state;
private String zip;
// getters and setters not shown...
}
如果我从mapping.xml和输入字符串中删除所有前面的字段到重复段,剩余的字符串被正确解组,然后被编组为json,我什至没有改变java类的实现,所以前面的字段保持未初始化,如预期的,但在编组后正确打印出来。我哪里做错了?
好的,我的骆驼代码在spring xml中,如下所示:
<route id="simple-route">
<!-- from id="request-file" uri="file://C:/mqdocuments/?fileName=response464.txt"/-->
<from id="request-file" uri="file://C:/mqdocuments/?fileName=request464.txt"/>
<log id="route-log-request" message="request: ${body}"/>
<setHeader headerName="CamelJmsDestinationName" id="_setHeader1">
<constant>queue://QM_TEST/INPUTQ?targetClient=1</constant>
</setHeader>
<to id="_to1" pattern="InOut" uri="websphere:queue:SYSTEM.DEFAULT.LOCAL.QUEUE?useMessageIDAsCorrelationID=true&replyTo=REPLYQ"/>
<log id="route-log-response" message="response: ${body}"/>
<transform>
<simple>${body}\0</simple>
</transform>
<unmarshal ref="parseTransactions464"/>
<marshal ref="jack"/>
<log id="route-log-json" message="jackson: ${body}"/>
</route>
所以基本上,当我从保存响应的文件中取消注释输入并将注释 mq 放置到端点时,解组是可以的,但是如果我将请求放入队列并获得响应,那么我希望能纠正问题通过简单地添加 EOF 字符的转换,因为没有它,它会给我我首先报告的错误。并且转换没有帮助,因为我不知道如何编写 EOF (ascii 26),但即使我弄清楚了,我也不确定它是否会有所帮助。