NewCoder
NewCoder

Reputation: 11

Mapping csv columns to composite Pojo classes

I am using univocity-parser library for this

class Person{

@Parsed(index=1)

String name;

@Parsed(index=2)

String age;

Address address;

}

class Address{

@Parsed(index=3)

String street;

String city;

}

BeanListProcessor rowProcessor = new BeanListProcessor(Person.class);

List beans = rowProcessor.getBeans();

Exception while mapping the csv columns to POJO class : com.univocity.parsers.common.DataProcessingException: Unable to set value to address field

Is there any other way to do it

Upvotes: 1

Views: 313

Answers (1)

Jeronimo Backes
Jeronimo Backes

Reputation: 6289

Use the @Nested annotation introduced in version 2.4.0, just do this:

class Person{
    @Parsed(index=1)
    String name;

    @Parsed(index=2)
    String age;

    @Nested
    Address address;
}

Upvotes: 1

Related Questions