#159 more than add or update on arrays

Dozer v5.2

My source or destination is a generated class with getters and setters.
However the arrays are presized since it is determined by a copybook size.
So I have a source and destination array with 100 elements.
I want dozer to copy or map each index.
Not add or update logic it is doing now.

I've worked with the mappings quite a bit and I get one of the following scenarios:
1) I get an array with 200 elements with the values from my source array starting at the 101 element.
2) I get an array with 102 elements (assuming only 2 of 100 elements in source array has a value) with my values starting at the 101 element
3) I get a null pointer exception because the source element has a null value in the array.

I want my two values copied from my source array to my destination array so that I have 100 element array with the first two positions having my values.

I've attached a couple unit tests to demonstrate a bit and if you can make them pass by only changing the mapping files then that is what I want.

I've struggled with collections in this way in the past without generated classes which leads doing extra work outside of dozer or hacking your beans up. It would be nice to have some more options/control



  • sdg

    sdg - 2009-01-05

    Array Mappings Unit Test

  • Vadim Shaigorodskiy


    For now, there are several ways to do right mapping:

    1. do not create dest array in the class.
    2. set copy-by-reference="true". Because String is an immutable object, changes in one array doesn't affect other array.

    This problem occurs, because your dest array was already initialized with 100 null's.
    - If you put flag relationship-type="non-cumulative", then dozer tries to update objects insdide and throws NPE
    - If you put relationship-type="cumulative" (which is default), the dozer simply adds 2 more elements to your's 100 length array.

  • Vadim Shaigorodskiy

    NPE bugfixg added. The other thing is default dozer behavior. If you think this behavior is not acceptable, please create a feature request.

  • dmitry (lv)

    dmitry (lv) - 2009-10-23
    • milestone: 888639 --> Dozer v5.2
    • assigned_to: nobody --> vadeg
    • status: open --> closed-fixed
  • dmitry (lv)

    dmitry (lv) - 2009-10-23

    The use case you have described is not currently supported and by introducing that we will break existing logic and correlation of array mappings and collection mappings. It is recommended to go with custom converters now.
    If you feel that this is a critical feature feel free to register feature request.


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks