pradeepsjsu / beanio

Automatically exported from code.google.com/p/beanio
Apache License 2.0
0 stars 0 forks source link

New instance of bean created everytime a segment is reused #129

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Hi,

I have a complex bean structure and I need to extract certain nested properties 
into a fixed length file in such order, that I have to reuse/redefine certain 
segments. Later I need to populate the java bean using previously stored fixed 
length file. Going from java to fixed lengths seems to do exacly what expected.
Mapping from fixed-length to Java is an issue as beanIO seems to create a new 
instance of nested bean everytime a segment is reused. It should check whether 
property which the segment is mapping to is null first and only if it is, it 
should create and assign a new instance of the nested bean.
See very simple example below(only for illustration, might not be sytactically 
correct):

JAVA CLASSES
package example;

public class Outer{
    Inner innerA;
    Inner innerB;
}

public class Inner{
    String a="a";
    String b="b";
    String c="c";
}

MAPPING XML:
<beanio xmlns="http://www.beanio.org/2012/03">
    <stream name="CashISATransferStatus" format="fixedlength">
        <record name="example" class="example.Outer">
            <segment name="innerA" class="example.Inner">
                <field name="a" length="1" />
            </segment>
            <segment name="innerB" class="example.Inner">
                <field name="a" length="1" />
            </segment>
            <segment name="innerA" class="example.Inner">
                <field name="b" length="1" />
            </segment>
            <segment name="innerB" class="example.Inner">
                <field name="b" length="1" />
            </segment>
            <segment name="innerA" class="example.Inner">
                <field name="c" length="1" />
            </segment>
            <segment name="innerB" class="example.Inner">
                <field name="c" length="1" />
            </segment>
        </record>
    </stream>
</beanio>           

JAVA to FLAT -all good,as expected
aabbcc

FLAT to JAVA - reusing of segments results in creation of a new instance of 
bean everytime

expected:{
innerA:{a:a, b:b, c:c}
innerB:{a:a, b:b, c:c}
}

actual:{
innerA:{a:null, b:null, c:c}
innerB:{a:null, b:null, c:c}
}

Original issue reported on code.google.com by voron.pa...@gmail.com on 25 Nov 2014 at 6:57