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.