*
The moose likes XML and Related Technologies and the fly likes jaxb marshall java to xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "jaxb marshall java to xml" Watch "jaxb marshall java to xml" New topic
Author

jaxb marshall java to xml

bruce truong
Greenhorn

Joined: Mar 14, 2011
Posts: 11
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

Joined: Aug 05, 2002
Posts: 61
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


Boney
SCJP, SCWCD
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: jaxb marshall java to xml
 
Similar Threads
how can we create new object using de-serlization in java ?
Objects involved in a cycle!
blocked threads
Using interface as a type
Passing subclass in the interface method