This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jaxb marshall java to xml

 
bruce truong
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

I am new to JAXB. I have been reading tutorials and how to all over. I want o generate something like this:
<AllClass>
<MyClass>
<Object1>
...
</Object1>
<Object2>
...
</Object2>
</MyClass>
<MyClass>
<Object1>
...
</Object1>
<Object2>
...
</Object2>
</MyClass>
</AllClass>

@XmlRootElement
public class MyClass{
private Object1 obj1;
private List<Object2> obj2;

public MyClass() {
}
public MyClass(Object1 obj1, List<Object2> obj2) {
this.obj1 = obj1;
this.obj2 = obj2;
}
}

Everything is working and happy. But now I want to extend it further by wrapping it in another object. This is where it's not working and I need to understand why. Below is the code:
(@XmlRootElement is removed from MyClass)

@XmlRootElement
public class AllClass{
private List<MyClass> classes;

public AllClass() {
}

public AllClass(List<MyClass> classes) {
this.classes= classes;
}
}

This is the error I got: javax.xml.bind.JAXBException: nor any of its super class is known to this context.

Can someone please explain to me why it works for MyClass with List<Object2> but not in AllClass. I even tried to remove "List" and still the same error.

Thanks in advance
bruce

Hello All,

I got it work now.

Thanks

(Edited to restore original post -- Paul C)
 
B Mampilli
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bruce,

I am trying to work with 2 XSDs (One inherits from the other).

Just wanted to know if jaxb supports this and generates the classes for marshaling and De-marshalling these files?

Any help here would be helpful.

Thanks
B. Mampilli
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic