POJO:
{@code} @XmlRootElement(name="entry") public class FeedEntry {public int myAttr1; // Element whose name in XML differs and is fully qualified with a name space @XmlElement(namespace="http://example.com", name="myAttr2Xml") public String myAttr2;} }
Parsing code:
{@code // Little Groovy code; // Normally you'd cache an instance to do the expensive initialization just once def entries = new GenericXmlToPojoParser().parseFrom("/feed/entry", xml, FeedEntry.class); assert entries.size() == 2; def entry1 = entries.iterator().next(); assert entry1.myAttr1 == 123 && "myValue2".equals(entry1.myAttr2);}
- add caching of JAXBContext, XPathExpression - implement validation as suggested in the BeanValidatingUnmarshalListener@see XmlElements @author jholy
|
|