java - Unmarshalling complex types using single JAXB annotated class -
I have the following XML to be used by my application:
& Lt; / Files & gt; & Lt; / PackageFiles & gt; To unmarshall with JAXB, I have defined the following two classes: Prefix @xmlRootElement (name = "PackageFiles") public class PackageFiles {@ XmlAttribute (name = "applicationGUID") private string ApplicationGUID; @ XmlElementWrapper (name = "files") @ XmlElement (name = "file") Private list & lt; File & gt; Files; } @ XmlRootElement (name = "file") public class file {@XmlAttribute (name = "name") private string name; }
It works great, but I was thinking that PackageFiles is a way to annotate the square so that I can convert the file in the class and instead & lt; File ... & gt; name in the attribute list element PackageFile class?
If this type of complexity is often encountered, then you might consider using the transformer Xslt In order to perform a unmarshalling in a way that you can easily manipulate it or you can make a file to the public static class within the package file:
public stable class file {@XmmElement Private string name; } Personally I like the XSLT method because it is a more intuitive and very easy to maintain with Java files which are in constant state.
Comments
Post a Comment