org.beanio.BeanReaderException: Record groups not supported by Unmarshallers
at org.beanio.internal.parser.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:191)
at org.beanio.internal.parser.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:89)
<stream name="orders" format="csv">
<group name="order" class="example.Order" minOccurs="0" maxOccurs="unbounded">
<record name="orderRecord" order="1" minOccurs="1">
<field name="recordType" rid="true" literal="Order" ignore="true" />
<field name="id" />
<field name="date" format="yyyy-MM-dd" />
<field name="amount" />
</record>
<record name="customer" class="example.Customer" order="2" minOccurs="1" maxOccurs="1">
<field name="recordType" rid="true" literal="Customer" ignore="true" />
<field name="firstName" />
<field name="lastName" />
</record>
<record name="items" class="example.Item" collection="list" order="3" minOccurs="1" maxOccurs="unbounded">
<field name="recordType" rid="true" literal="Item" ignore="true" />
<field name="name" />
<field name="quantity" />
<field name="amount" />
</record>
</group>
</stream>// getters + setters not shown
// imports also not shown
package example;
public class Order {
String id;
Date date;
BigDecimal amount;
Customer customer;
List<Item> items;
}
public class Customer {
String firstName;
String lastName;
}
public class Item {
String name;
int quantity;
BigDecimal amount;
}
package example;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;
import org.beanio.StreamFactory;
import org.beanio.Unmarshaller;
import org.junit.BeforeClass;
import org.junit.Test;
/**
* @author Nico Schlebusch
*/
public class TestBeanIO {
private static StreamFactory factory;
/**
* @throws java.lang.Exception
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception {
factory = StreamFactory.newInstance();
assertThat(factory, is(notNullValue()));
factory.loadResource("mapping.xml");
}
@Test
public void test() {
final String data =
"Order,101,2012-02-01,5.00\r\n" +
"Customer,John,Smith\r\n" +
"Item,Apple,2,2.00\r\n" +
"Item,Orange,1,1.00\r\n" +
"Order,102,2012-02-01,3.00\r\n" +
"Customer,Jane,Johnson\r\n" +
"Item,Ham,1,3.00";
final Unmarshaller unmarshaller = factory.createUnmarshaller("orders");
final Object object = unmarshaller.unmarshal(data);
assertThat(object, is(notNullValue()));
}
}
I think you need to use the reader, not unmarshaller. Unmarshallers work with 1 record only.
--
You received this message because you are subscribed to the Google Groups "beanio-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beanio+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.