Details
Description
For some reason, the JDK 1.5 enums do not seem to be marshalled, could somebody tell me what I have done wrong?
Here is an enum, a class that uses the enum and a method that marshalls a test:
public enum CastorState {
ACTIVE,
INACTIVE
}
public class CastorTest {
private String name;
private CastorState state;
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public CastorState getState() { return state; }
public void setState(CastorState state) { this.state = state; }
public static void main(String[] arg) {
try {
CastorTest test = new CastorTest();
test.setName("My Name is");
test.setState(CastorState.ACTIVE);
LocalConfiguration.getInstance().getProperties().setProperty("org.exolab.castor.indent", "true");
Marshaller.marshal(test, new FileWriter("castor-test.xml"));
} catch (MarshalException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ValidationException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
The result is a file containing this:
<?xml version="1.0" encoding="UTF-8"?>
<castor-test>
<name>My Name is</name>
</castor-test>
Nothing about "state"... Why?
Is it a known issue or am I doing something wrong.
Many thanks for your help,
Best regards from a rainy London!
Benoit
Attachments
Issue Links
| This issue is duplicated by: | ||||
| CASTOR-991 | Support for Java5 Enum |
|
|
|
I have run into a very similar problem when I try to map Java 1.5 enumerations using Castor. However, unmarshalling seems to work fine (note that you have to disable the default constructor check in the mapping file). When marshalling, only the element name specified in the bind-xml is displayed - i.e. if the original string was <day>MONDAY</day>, the unmarshalled object would be an enumerated Day object but marshalling the same object would only produce <day />. It seems like the toString() method on the enumerated type is not being called by the marshaller because I've tried overriding the default toString() behaviour in the enumerated type to return something different and it had no effect on the marshalled XML string.