Unmarshalling a record group throws org.beanio.BeanReaderException: Record groups not supported by Unmarshallers

787 views
Skip to first unread message

Nico Schlebusch

unread,
Jan 8, 2016, 4:19:34 AM1/8/16
to beanio-users
Hi everyone

I'm trying to configure a mapping.xml file to read (unmarshal) a record group. According to sections:
  • 4.2.3. Record Grouping and
  • 4.8.1. Mapping Bean Objects that Span Multiple Records
from the reference guide, this should be possible.

I'm currently trying to run the example from section 4.8.1, but get the above exception:

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)

Is there something misconfigured in the example code or is it just not possible to unmarshal a record group? I'm really hoping that something is misconfigured. I have seen other posts about record groups that seem to be working.

For easy reference, here is the mapping.xml

  <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>

The Java objects:

// 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;
}

And the test class:

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()));
 
}

}


Thank you
Nico

Vitalii Tymchyshyn

unread,
Jan 8, 2016, 8:01:39 AM1/8/16
to beanio-users

I think you need to use the reader, not unmarshaller. Unmarshallers work with 1 record only.


Пт, 8 січ. 2016 04:19 Nico Schlebusch <nico...@gmail.com> пише:
--
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.

Nico Schlebusch

unread,
Jan 8, 2016, 8:36:46 AM1/8/16
to beanio-users, v...@tym.im
Hi Vitalii

Thank you! Using the BeanReader solved the problem.

Nico

Reply all
Reply to author
Forward
0 new messages