Announcement Announcement Module
Collapse
No announcement yet.
mapping one line to multiple objects Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • mapping one line to multiple objects

    Spring batch Users,

    Is it possible to map one input line in a file to multiple objects. I guess FieldSetMappers can map input field set to only one object, because return type is only one object. Is there way to achieve the mapping to multiple objects without writing custom code in spring batch.
    e.g
    mapping

    John Does|050780| 15 Green St|Liousana|USA

    User
    {
    string name
    date dob
    }

    Address
    {
    String street;
    String state;
    Country;
    }

  • #2
    You could map to a custom object that hold the inner objects:
    Code:
    public class UserAddress {
        private User user;
        private Address address;
    }
    If you want to use BeanWrapperFieldSetMapper instead of a custom mapper, then you can give the property names as, for example, "user.name" and it will automatically map to the "name" within the "user" of the UserAddress. Note that you'll need to instantiate the inner User and Address objects from the UserAddress constructor so that you don't get null pointers.
    Last edited by DHGarrette; Aug 19th, 2009, 09:53 PM.

    Comment


    • #3
      Thank you for the response. BeanWrapperFieldSetMapper does work but the problem now I face is that it doesn't does the data conversion correctly. e.g if the source field type is string and value is 0 and target field type is double. It throws NumberFormatException. Can I just write data converters for BeanWrapperFieldSetMapper? If so, please point me to some examples.

      Thanks
      W

      Comment

      Working...
      X