Note that there are some explanatory texts on larger screens.

plurals
  1. POJAXB unmarshalling not working
    primarykey
    data
    text
    <p>I´ve set up a project to test marshalling for another project. Marshalling is working. I get the correct xml file, but unmarshalling is NOT working. I only get the Relation name (String). The attributes and functional dependencies are missing.</p> <p>EDIT: Here is the source: <a href="http://dl.dropbox.com/u/18039229/JaxbMarshallingSrc.zip" rel="nofollow">Sourcecode</a></p> <p>Please take a look at the classes:</p> <p>Main:</p> <pre><code>public class Main { public static void main(String[] args){ Relation db = new Relation(); Attribute a1 = new Attribute("Attribute 1", true, false); Attribute a2 = new Attribute("Attribute 2", false, false); Attribute a3 = new Attribute("Attribute 3", false, true); db.addAttribute(a1); db.addAttribute(a2); db.addAttribute(a3); ArrayList&lt;String&gt; src = new ArrayList&lt;String&gt;(); src.add("Attribute 1"); ArrayList&lt;String&gt; dest = new ArrayList&lt;&gt;(); dest.add("Attribute 2,Attribute 3"); FDs f1 = new FDs(src, dest); db.addFd(f1); exportToXml saver = new exportToXml(); try { saver.SaveDbNow(db); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } //Export again to test output Relation db2 = new Relation(); importFromXml reader = new importFromXml(); try { reader.ReadDbNow(db2); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } try { saver.SaveDbNow2(db2); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } </code></pre> <p>Relation:</p> <pre><code>@XmlRootElement(name = "Relation") public class Relation { @XmlElement(name = "RelName") String name; @XmlElement(name = "Attribute") private ArrayList&lt;Attribute&gt; attrList; @XmlElement(name = "FD") private ArrayList&lt;FDs&gt; fdsList; public Relation() { this.attrList = new ArrayList&lt;&gt;(); this.fdsList = new ArrayList&lt;&gt;(); this.name = "Testname"; } public Relation(String name, ArrayList&lt;Attribute&gt; attrList, ArrayList&lt;FDs&gt; fdsList) { super(); this.attrList = attrList; this.fdsList = fdsList; } @XmlTransient public ArrayList&lt;Attribute&gt; getAttrList() { return attrList; } public void setAttrList(ArrayList&lt;Attribute&gt; attrList) { this.attrList = attrList; } @XmlTransient public ArrayList&lt;FDs&gt; getFdsList() { return fdsList; } public void setFdsList(ArrayList&lt;FDs&gt; fdsList) { this.fdsList = fdsList; } public void addAttribute(Attribute a) { this.attrList.add(a); } public void addFd(FDs fd) { this.fdsList.add(fd); } } </code></pre> <p>Attribute:</p> <pre><code>public class Attribute { @XmlElement( name = "Attributename") private String name; @XmlElement( name = "isPK") private boolean isPK; @XmlElement( name = "isFK") private boolean isFK; public Attribute(){ } public Attribute(String name, boolean isPK, boolean isFK) { super(); this.name = name; this.isPK = isPK; this.isFK = isFK; } @XmlTransient public String getName() { return name; } public void setName(String name) { this.name = name; } @XmlTransient public boolean isPK() { return isPK; } public void setPK(boolean isPK) { this.isPK = isPK; } @XmlTransient public boolean isFK() { return isFK; } public void setFK(boolean isFK) { this.isFK = isFK; } } </code></pre> <p>FD:</p> <pre><code>public class FDs { @XmlElement( name = "Source") private ArrayList&lt;String&gt; src; @XmlElement( name = "Destination") private ArrayList&lt;String&gt; dest; public FDs(){ } public FDs(ArrayList&lt;String&gt; src, ArrayList&lt;String&gt; dest) { super(); this.src = src; this.dest = dest; } @XmlTransient public ArrayList&lt;String&gt; getSrc() { return src; } public void setSrc(ArrayList&lt;String&gt; src) { this.src = src; } @XmlTransient public ArrayList&lt;String&gt; getDest() { return dest; } public void setDest(ArrayList&lt;String&gt; dest) { this.dest = dest; } } </code></pre> <p>Export:</p> <pre><code>public class exportToXml { public void SaveDbNow(Object saveMe) throws Exception { JAXB.marshal(saveMe, new File("test.xml")); } public void SaveDbNow2(Object saveMe) throws Exception { JAXB.marshal(saveMe, new File("test2.xml")); } } </code></pre> <p>Import:</p> <pre><code>public class importFromXml { public void ReadDbNow(Object readMe) throws Exception { readMe = JAXB.unmarshal(new FileInputStream("test.xml"), Relation.class); } } </code></pre> <p>Thanks in advance!</p> <p>EDIT: Output1:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt; &lt;Relation&gt; &lt;RelName&gt;Testname&lt;/RelName&gt; &lt;Attribute&gt; &lt;Attributename&gt;Attribute 1&lt;/Attributename&gt; &lt;isPK&gt;true&lt;/isPK&gt; &lt;isFK&gt;false&lt;/isFK&gt; &lt;/Attribute&gt; &lt;Attribute&gt; &lt;Attributename&gt;Attribute 2&lt;/Attributename&gt; &lt;isPK&gt;false&lt;/isPK&gt; &lt;isFK&gt;false&lt;/isFK&gt; &lt;/Attribute&gt; &lt;Attribute&gt; &lt;Attributename&gt;Attribute 3&lt;/Attributename&gt; &lt;isPK&gt;false&lt;/isPK&gt; &lt;isFK&gt;true&lt;/isFK&gt; &lt;/Attribute&gt; &lt;FD&gt; &lt;Source&gt;Attribute 1&lt;/Source&gt; &lt;Destination&gt;Attribute 2,Attribute 3&lt;/Destination&gt; &lt;/FD&gt; </code></pre> <p></p> <p>Output2:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt; &lt;Relation&gt; &lt;RelName&gt;Testname&lt;/RelName&gt; &lt;/Relation&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload