0

We have a Spring Integration application which uses a JDBC poller together with a RowMapper to read from a database and output a collection of domain objects (presuming the result set returned more than one row).

The domain objects are then marshalled into XML. When using Castor as the marshaller, this works ok, and the XML represents a collection of the domain objects:

<array-list>
   <order>
     <orderID>23940210</orderID>
     ...
   </order>
   <order>
   ...
</array-list>

We now wish to switch from Castor to JAXB. This is the definition of the JAXB marshaller in XML:

<oxm:jaxb2-marshaller id="jaxbMarshallerBean">
   <oxm:class-to-be-bound name="com.mycompany.Order" />
</oxm:jaxb2-marshaller>

... the JAXB marshaller is used as the transformer used in the Spring Integration chain ..

<int:chain input-channel="input" output-channel="output-jms">
    <si-xml:marshalling-transformer id="defaultMarshaller" marshaller="jaxbMarshallerBean" />
</int:chain>

and of course the domain class is annotated:

@XmlRootElement(namespace ="Order")  
public class Order{
     ...

   @XmlElement(name="OrderID")    
   public String getOrderId() {
       return orderId;
   }

Now, the following exception is thrown:

org.springframework.oxm.UncategorizedMappingException: 
Unknown JAXB exception; 
nested exception is javax.xml.bind.JAXBException: 
class java.util.ArrayList nor any of its super class is known to this context.

It looks like JAXB does not like the fact that it is handling a collection of domain objects. What is the correct way to configure or handle this?

Thanks very much

user1052610
  • 4,440
  • 13
  • 50
  • 101

1 Answers1

0

Surely you want an unmarshalling transformer to go from XML to POJO.

I don't know if there is a way to configure JAXB to handle it directly, but you could add an XPath splitter before the unmarshaller and an aggregator after it.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179