Skip to main content

How to know when extra tags are being read and thrown away?

4 replies [Last post]
mnroder
Offline
Joined: 2005-07-18

How do I know when "extra" tags are being read and thrown away? By extra I mean when the XML file contains tags that do not map into the java objects.

Example POJO:
public class SimpleObject {
String dataOne;
String dataTwo;
}

Input:

one
two
three

How do I know when dataThree is being processed and it does not map into the Java POJO?

My use case is going to be geared towards unit testing to validate I have a complete map of the XML files. I can not depend on the schema as that conversion might be old and if the schema changes, the POJOs would get out of sync. The goal is to have a test that will catch this case.

Thanks

Mark

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kohsuke
Offline
Joined: 2003-06-09

You can register ValidationEventHandler to Unmarshaller to get notifications whenever an element is thrown away.

mnroder
Offline
Joined: 2005-07-18

This works for child elements, but not for attributes or for data that maps to an enum that is not valid.

I tried to report an issue on this and provided some test cases. Not sure if I reported an issue for the code base or for the web site. It is located: https://jaxb2-sources.dev.java.net/issues/show_bug.cgi?id=1

Mark

kohsuke
Offline
Joined: 2003-06-09

Ah, perhaps what you might want to do is to enable validation, so that the document is checked against the schema as it is unmarshalled.

See Unmarshaller.setSchema()

kohsuke
Offline
Joined: 2003-06-09

And please don't use jaxb2-source for filing issues. It should go to http://jaxb.dev.java.net/