fyzhou / beanio

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

Lazy repeating segments should return null instead of an empty collection #66

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi Kevin,

Thanks for your continues support towards BeanIO API.

I got the latest version of BeanIO 2.0.3 API, and I am noticing few things. We 
have a property 'Lazy' that can be set at segment level. If 'lazy=true' then it 
will not create objects if all fields are empty.

What I noticed is, if a segment has a segment with in it, then even if all the 
fields are empty and lazy=true, beanIO is creating empty objects. 

For Example:

<stream name="sample4" format="fixedlength">
        <record name="Product" class="com.Product">
            <field name="name" length="10"/>
             <segment name="currencyList" class="com.Currency" collection="list" minOccurs="10" maxOccurs="10" lazy="true">
                <field name="name" length="10"/>
                <field name="amt" length="10"/>
                <segment name="linkedCurrencyList" class="com.LinkedCurrency" collection="list" minOccurs="5" maxOccurs="5" lazy="true">
                <field name="currencyCode" length="10"/>
                </segment>
             </segment>
        </record>
 </stream>

Product class:
public class Product {

    String name;
    List<Currency> currencyList;
}

public class Currency {

    String name;
    Double amt;
    List<LinkedCurrency> linkedCurrencyList;
}

public class LinkedCurrency {
    String currencyCode;
}

attached is the sample fixed length message.

Though I have only one product in the fixed length message, BeanIO is 
generating 4 empty product objects. In a high volume test, creation of these 
empty objects can put overhead on CPU due to GC runs.

I further tested with few more scenarios, the 'lazy=true' works fine when there 
are no segments with in segments.

For example:
<stream name="sample5" format="fixedlength">
        <record name="Product" class="com.beanio.testpojo.multiplesegments.Product">
        <field name="name" length="10"/>
             <segment name="currencyList" class="com.beanio.testpojo.multiplesegments.Currency" collection="list" minOccurs="10" maxOccurs="10" lazy="true">
                <field name="name" length="10"/>
                <field name="amt" length="10"/>
             </segment>
        </record>
 </stream>

but for the above mapping, when I have the fixed length message like below
<start>shoe      USD       100.0               0.0                 0.0          
       0.0                 0.0                 0.0                 0.0          
       0.0                 0.0                 0.0       <end>

BeanIO still creates 9 empty Currency objects. 

Is there a way to avoid creation of empty objects when using fixed length 
messages? Do you recommend any suggestions? Is there a way we can treat 0 or 
0.0 as null or blank?

Once again great work.

Thanks,
Arcot

Original issue reported on code.google.com by kevin.s...@gmail.com on 15 Mar 2013 at 2:44

GoogleCodeExporter commented 9 years ago
See original post from forum for additional attachments: 
https://groups.google.com/forum/?fromgroups=#!topic/beanio/RFvhMiYzJgM

Original comment by kevin.s...@gmail.com on 15 Mar 2013 at 2:44

GoogleCodeExporter commented 9 years ago

Original comment by kevin.s...@gmail.com on 15 Mar 2013 at 3:00

GoogleCodeExporter commented 9 years ago
Changed to enhancement.  The lazy property only applies to bean objects bound 
to a segment, and not collections.  A separate property will be created for 
instructing BeanIO to use null for empty collections.

Original comment by kevin.s...@gmail.com on 16 Mar 2013 at 7:29

GoogleCodeExporter commented 9 years ago
Modification will result in minor backwards incompatibility.  Moving to 
2.1.0.M1.

A single 'lazy' property will apply to both the collection and class of a 
segment.  This results in changed behavior from 2.0.x where a lazy segment 
bound to a collection would still return an empty collection.  2.1.x and higher 
will return null instead.

Original comment by kevin.s...@gmail.com on 16 Mar 2013 at 9:35

GoogleCodeExporter commented 9 years ago
Modified title.

Original comment by kevin.s...@gmail.com on 16 Mar 2013 at 9:39

GoogleCodeExporter commented 9 years ago
2.1.0.M1 snapshot JAR attached.

Original comment by kevin.s...@gmail.com on 16 Mar 2013 at 10:27

Attachments:

GoogleCodeExporter commented 9 years ago

Original comment by kevin.s...@gmail.com on 27 Apr 2013 at 11:45