I am using JAXB unmarshal
method to convert XML data into java objects. Code works but when there is invalid data in one of the XML tags, the method throws exceptions and stops immediately e.g.
org.springframework.oxm.UnmarshallingFailureException: JAXB unmarshalling exception; nested exception is javax.xml.bind.UnmarshalException
- with linked exception:
[com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 2 of 2-byte UTF-8 sequence.]
org.springframework.oxm.UnmarshallingFailureException: JAXB unmarshalling exception; nested exception is javax.xml.bind.UnmarshalException
- with linked exception:
[org.xml.sax.SAXParseException; lineNumber: 6; columnNumber: 45; An invalid XML character (Unicode: 0x1) was found in the element content of the document.]
Instead of throwing exception straight away, what I want is to convert the XML data as much as it can by replacing invalid data to a space or empty string (i.e. strip them and continue).
Is there a way to make the unmarshaler do that?
Or else try catching the exceptions would be OK (less ideal) if there is a way to let the unmarshaler continues from where it stopped.
Obviously pre-processing the XML to strip out all invalid data first before unmarshaling is another way, not preferable unless there is no other way as it just means processing the XML data twice.
Welcome to use other unmarshaler if JAXB cannot do what I want.