Results 1 to 2 of 2
  1. #1
    btran007 is offline Member
    Join Date
    Mar 2011
    Posts
    3
    Rep Power
    0

    Default how to marshal complex object

    Hello All,

    I am trying JAXB for the first time. I have been reading tutorials and how to all over. I got as far as this:

    @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
    btran

  2. #2
    btran007 is offline Member
    Join Date
    Mar 2011
    Posts
    3
    Rep Power
    0

    Default Re: how to marshal complex object

    I got it to work now. I forgot to change the class name from MyClass to AllClass.

    btran

Similar Threads

  1. marshal/unmarshal java object
    By cpk in forum XML
    Replies: 0
    Last Post: 08-14-2011, 01:07 PM
  2. How complex is too complex for a single class?
    By manji51 in forum AWT / Swing
    Replies: 7
    Last Post: 07-08-2011, 08:20 PM
  3. Replies: 2
    Last Post: 06-01-2011, 10:44 AM
  4. Complex Factory with @AssistedInjection
    By veronique in forum Advanced Java
    Replies: 5
    Last Post: 05-18-2011, 10:45 AM
  5. Complex file input
    By JMaste in forum Advanced Java
    Replies: 4
    Last Post: 12-08-2010, 04:55 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •