简体   繁体   English

BeanIO定长记录中的键值映射

[英]Key-value mapping in BeanIO fixed-length record

I have the following specification for a fixed-length data file (refer to record-C type of specification, page 4) 对于定长数据文件,我具有以下规范 (请参阅第4页的record-C类型的规范)

a second part, having a length of 1,800 characters, consisting of a table of 75 elements to be used for the display of the only data present in the communication; 第二部分的长度为1800个字符,由75个元素的表组成,用于显示通信中唯一的数据; each of these elements is constituted by a field-code of 8 characters and by a field-value of 16 characters 这些元素中的每一个都由8个字符的域代码和16个字符的域值组成

It means that the first 89 characters (omitted in the above summary) are plain old fixed-length and then, for the remaining 1800, I have to take them into groups of key-value pairs each counting up to 24 characters. 这意味着前89个字符(在上面的摘要中省略了)是普通的固定长度,然后,对于剩下的1800个字符,我必须将它们分成每组最多包含24个字符的键值对组。 Blank spaces are trimmed and empty pairs are not considered in the process. 空格被修剪,并且在此过程中不考虑空对。

Ideally, my bean may be constructed like 理想情况下,我的豆子可以像

public class RecordC{

    private List<Pair<String, String>> table = new ArrayList<>(MAX_TABLE_SIZE); //I don't want to use Map **yet**

}

Something can be eg Apache Common's Pair<String,String> or anything suitable for KVP mapping. 例如Apache Common的Pair<String,String>或适用于KVP映射的任何东西。

I understand that I can create a whole TypeHandler that takes the full 1800 bytes but I wanted to exploit the power of BeanIO. 我知道我可以创建一个完整的TypeHandler,占用整个1800个字节,但我想利用BeanIO的功能。

Here is what I have done so far 这是我到目前为止所做的

    <record name="RECORD_C" class="it.csttech.ftt.data.beans.ftt2017.RecordC" order="3" minOccurs="1" maxOccurs="1" maxLength="2000">
        <field name="tipoRecord" rid="true" at="0" ignore="true" required="true" length="1" lazy="true" literal="C" />

        <field name="cfContribuente" at="1" length="16" align="left" trim="true" lazy="true" />
        <field name="progressivoModulo" at="17" length="8" padding="0" align="right" trim="true" lazy="true" />
        <field name="spazioDisposizioneUtente" at="25" length="3" align="left" trim="true" lazy="true" />
        <field name="spazioUtente" at="53" length="20" align="left" trim="true" lazy="true" />

        <field name="cfProduttoreSoftware" at="73" length="16" align="left" trim="true" lazy="true" />

        <segment name="table" collection="list" lazy="true" class="org.apache.commons.lang3.tuple.ImmutablePair">
            <field name="key" type="java.lang.String" at="0" length="8" trim="true" lazy="true" setter="#1" />
            <field name="value" type="java.lang.String" at="8" length="16" trim="true" lazy="true" setter="#2" />
        </segment>

        <field name="terminatorA" at="1897" length="1" rid="true" literal="A" ignore="true" />
    </record>

Unfortunately this does not work in testing. 不幸的是,这在测试中不起作用。 I get only a single record in the list, decoded at positions [0-7] and [8-23] instead of expected [89-113][114-???][....][....] 我在列表中仅得到一条记录,在位置[0-7]和[8-23]处解码,而不是预期的[89-113] [114-???] [....] [.... ]

Question is: how do I in BeanIO declare repeating fixed-length fields? 问题是:如何在BeanIO中声明重复的固定长度字段?

I have currently resolved my unmarshalling problem by removing all at attributes in the RecordC specifications. 我目前已通过删除RecordC规范中的所有at属性来解决我的编组问题。 As I found out, the "at" attribute is absolute to the record and not relative to the repeating segment. 正如我发现的那样,“ at”属性对于记录是绝对的,而不是相对于重复段。 However this forced me to add some ignored fields in the unmarshalling at the sole cost of a few ignore s. 但是,这迫使我在解组中添加一些被忽略的字段,而仅需花费几个ignore

I will test the marshalling against the official controller once I have data 掌握数据后,我将对官方控制人员进行编组测试

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM