users@jaxb.java.net

java 5 enum type serialization problem

From: Bartek Wasko <bartek_at_consol.pl>
Date: Mon, 16 Oct 2006 17:23:33 +0200

Hi,

I have generated a model using xjc, based on following schema:

<xs:simpleType name="enumType">
    <xs:restriction base="xs:string">
      <xs:enumeration value="ENGINEER"/>
      <xs:enumeration value="CUSTOMER"/>
      <xs:enumeration value="ADMIN"/>
    </xs:restriction>
  </xs:simpleType>

The generated enum class is as follows:

@XmlEnum
public enum EnumType {

    ADMIN,
    CUSTOMER,
    ENGINEER;

    public String value() {
        return name();
    }

    public static EnumType fromValue(String v) {
        return valueOf(v);
    }

}

but if I try to serialize it using this:

try {
            JAXBContext ctx = JAXBContext.newInstance("generated");
            Marshaller mar = ctx.createMarshaller();
            try {
                mar.marshal(EnumType.ADMIN, new
FileOutputStream("c:\\test.xml"));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        } catch (JAXBException e) {
            e.printStackTrace();
        }

I get :

javax.xml.bind.JAXBException: test.EnumType nor any of its super class
is known to this context

If I add jaxb.index with this class name, it will result in error
message sayign that I have to mark my class with XmlRootElement annotation.
Indeed, after doing this, it works. But I do not want to do such
additional manipulation , I want to have my model automatically
generated and usefull without any changes.
Is it possible in this particular case??

I would appreciate any hints

bartek

-- 
**********************************************
ConSol*
Consulting & Solutions Software Poland
ul. Bronowicka 10A, 30-084 Kraków
tel. +48 (012) 6231525
bartek.wasko_at_consol.pl
http://www.consol.de
**********************************************