OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Problem using JAXB (from Sun)

[ Lists Home | Date Index | Thread Index ]
  • To: xml-dev@lists.xml.org
  • Subject: Problem using JAXB (from Sun)
  • From: Mukul Gandhi <mukul_gandhi@yahoo.com>
  • Date: Thu, 11 Aug 2005 22:46:32 -0700 (PDT)
  • Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:Received:Date:From:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=M+9YMpdY/Zf7c+ALjChpXcuDjZ95vIzWXgpVlQgPhqZlSGSERSyR5w56Hb5FNiqxeSE6n1nC2ryvpE/6Kmr4Pbct9iNG6YpRB5c87xdo0pKSSNlubsLiOMGFnWgzPEb55DBhq5tJpPm/X8Zu01FmxX04NN7XrlDsgNgFMOEfn6s= ;
  • In-reply-to: <f8da4eba050811160266e32c39@mail.gmail.com>

I have got a Java object, which I want to marshal to
XML file finally.

Below is the JAXB code I have written so far -

import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;

public class CatalogueMain {
  public static void main(String[] args)
  {
     CatalogueCategory catalogue_category =
                       new CatalogueCategory(
                       1,
                       "Computer Products",
                       "Computer Product Category",
                       -1
					   );

     CatalogueEntry catalogue_entry =
                    new CatalogueEntry(
                    1,
                    1,
                    "Hard Disk",
                    "Computer Hard Disk",
                    "Technical vetting",
                    "Business authorization",
                    55,
                    "GBP",
                    1,
                    "dummy_image_url",
                    new Date(2005,5,8),
                    "procure"
					);

     //create a Marshaller and marshal to standard
output
     try
     {
        JAXBContext jc =
JAXBContext.newInstance("generated");

        Marshaller m = jc.createMarshaller();
	    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,
Boolean.TRUE);
        m.marshal(catalogue_entry, System.out);
     }
     catch(Exception ex)
     {
        ex.printStackTrace();
     }
  }
}

When I run this program, I am getting following
exception -

javax.xml.bind.MarshalException: the object parameter
to marshal() is not marsha
llable
        at
generated.impl.runtime.MarshallerImpl.marshal(MarshallerImpl.java:88)

        at
javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshal
lerImpl.java:66)
        at CatalogueMain.main(CatalogueMain.java:47)

Can somebody please tell where could be the problem?

The CatalogueEntry class definition is -
public class CatalogueEntry extends EntryAttributes
implements java.io.Serializable {

	/**
	 * Constructor for CatalogueEntry
	 */
	public CatalogueEntry() {
	}

	/**
	Catalogue builds
	 */
	private ArrayList associatedBuilds = null;

	/**
	Catalogue products
	 */
	private ArrayList associatedProducts = null;

	/**
	Catalogue roles
	 */
	private ArrayList associatedRoles = null;

	/**
	Category id
	 */
	private int catalogueCategoryId = 0;

	/**
	Category name
	 */
	private String catalogueCategoryName = null;

	/**
	 * Field partNumber
	 */
	private String partNumber = null;

	/**
	Type of the catalogue entry.
	1= Generic Catalogue entry
	2= Service
	 */
	private int catalogueEntryType = 0;

	/**
	Constructor used for creating object to be used while
inserting record


	 * @param catalogueEntryId int
	 * @param catalogueCategoryId int
	 * @param name String
	 * @param description String
	 * @param techvet String
	 * @param businessAuthorization String
	 * @param price double
	 * @param currency String
	 * @param currencyID int
	 * @param imageURL String
	 * @param lastOrderDate Date
	 * @param performAction String
	 */
	public CatalogueEntry(
		int catalogueEntryId,
		int catalogueCategoryId,
		String name,
		String description,
		String techvet,
		String businessAuthorization,
		double price,
		String currency,
		int currencyID,
		String imageURL,
		Date lastOrderDate,
		String performAction) {
		super(
			catalogueEntryId,
			name,
			description,
			techvet,
			businessAuthorization,
			lastOrderDate,
			imageURL,
			price,
			currency,
			currencyID,
			performAction);
		this.catalogueCategoryId = catalogueCategoryId;

	}


	/**
	 * Constructor for CatalogueEntry
	 * @param catalogueEntryId int
	 * @param catalogueCategoryId int
	 * @param catalogueCategoryName String
	 * @param name String
	 * @param description String
	 * @param techvet String
	 * @param businessAuthorization String
	 * @param price double
	 * @param currency String
	 * @param currencyID int
	 * @param catalogueStatus String
	 * @param imageURL String
	 * @param lastOrderDate Date
	 * @param standardStatus String
	 * @param catalogueStatusId String
	 */
	public CatalogueEntry(
		int catalogueEntryId,
		int catalogueCategoryId,
		String catalogueCategoryName,
		String name,
		String description,
		String techvet,
		String businessAuthorization,
		double price,
		String currency,
		int currencyID,
		String catalogueStatus,
		String imageURL,
		Date lastOrderDate,
		String standardStatus,
		int catalogueStatusId) {

		super(
			catalogueEntryId,
			name,
			description,
			techvet,
			businessAuthorization,
			catalogueStatus,
			catalogueStatusId,
			lastOrderDate,
			imageURL,
			standardStatus,
			price,
			currency,
			currencyID);
		this.catalogueCategoryId = catalogueCategoryId;
		this.catalogueCategoryName = catalogueCategoryName;

	}

	/**
	Access method for the associatedBuilds property.

	@return   the current value of the associatedBuilds
property
	 */
	public ArrayList getAssociatedBuilds() {
		return associatedBuilds;
	}

	/**
	Sets the value of the associatedBuilds property.

	@param aAssociatedBuilds the new value of the
associatedBuilds property
	 */
	public void setAssociatedBuilds(ArrayList
aAssociatedBuilds) {
		associatedBuilds = aAssociatedBuilds;
	}

	/**
	Access method for the associatedProducts property.

	@return   the current value of the associatedProducts
property
	 */
	public ArrayList getAssociatedProducts() {
		return associatedProducts;
	}

	/**
	Sets the value of the associatedProducts property.

	@param aAssociatedProducts the new value of the
associatedProducts property
	 */
	public void setAssociatedProducts(ArrayList
aAssociatedProducts) {
		associatedProducts = aAssociatedProducts;
	}

	/**
	Access method for the associatedRoles property.

	@return   the current value of the associatedRoles
property
	 */
	public ArrayList getAssociatedRoles() {
		return associatedRoles;
	}

	/**
	Sets the value of the associatedRoles property.

	@param aAssociatedRoles the new value of the
associatedRoles property
	 */
	public void setAssociatedRoles(ArrayList
aAssociatedRoles) {
		associatedRoles = aAssociatedRoles;
	}

	/**
	Access method for the catalogueEntryType property.

	@return   the current value of the catalogueEntryType
property
	 */
	public int getCatalogueEntryType() {
		return catalogueEntryType;
	}

	/**
	Sets the value of the catalogueEntryType property.

	@param aCatalogueEntryType the new value of the
catalogueEntryType property
	 */
	public void setCatalogueEntryType(int
aCatalogueEntryType) {
		catalogueEntryType = aCatalogueEntryType;
	}

	/**
	@return String
	Returns string representation of object

	 */
	public String toString() {
		return null;
	}

	/**
	 * Method getCatalogueCategoryId
	 * @return int
	 */
	public int getCatalogueCategoryId() {
		return catalogueCategoryId;
	}

	/**
	 * Method getCatalogueCategoryName
	 * @return String
	 */
	public String getCatalogueCategoryName() {
		return catalogueCategoryName;
	}

	/**
	 * Method setCatalogueCategoryId
	 * @param i int
	 */
	public void setCatalogueCategoryId(int i) {
		catalogueCategoryId = i;
	}

	/**
	 * Method setCatalogueCategoryName
	 * @param string String
	 */
	public void setCatalogueCategoryName(String string) {
		catalogueCategoryName = string;
	}

	/**
	 * Method getPartNumber
	 * @return String
	 */
	public String getPartNumber() {
		return partNumber;
	}

	/**
	 * Method setPartNumber
	 * @param string String
	 */
	public void setPartNumber(String string) {
		partNumber = string;
	}

}

I'll be grateful for any help.

Regards,
Mukul




		
____________________________________________________
Start your day with Yahoo! - make it your home page 
http://www.yahoo.com/r/hs 
 




 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS