Client sends 50k customers in an xml file. I use Spring Batch’s JaxBMarshaller and run in a Spring Batch job.
Spring batch job gets a file, processes, and writes.
Problem is, it’s ALL or NONE validation with jaxb. If I have 50k objects and only 2 of them fail validation, I still need 49,998 objects to be processed by business.
There’s a class, javax.xml.bind.ValidationEventHandler; you can set it to JaxBMarshaller but it only returns true or false and provides no access to the object being marshaled.
I also added on the chunk Reader; error still throws.
Sample schema:
<xs:element name="CustomerLists">
<xs:complexType>
<xs:sequence>
<xs:element name="Customer" maxOccurs="unbounded" type="Customer"/>
</xs:sequence>
</xs:complexType>
</xs:element>
Sample Xml:
<a:CustomerLists xmlns:a="http://foo.com">
<a:Customer>
...
...
...
</a:Customer>
<a:Customer>
...
...
...
</a:Customer>
<a:Customer>
...
...
...
</a:Customer>
</a:CustomerLists>
Suggestions?
The
javax.xml.bind.ValidationEventHandleris the correct mechanism to use with JAXB. You can access the problematic object for an unmarshal operation through theValidationEvent:For More Information