• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

jaxb marshall java to xml

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic