castor

JDK 1.5 enum are not marshalled

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 0.9.9 M2, 1.1, 1.1.1
  • Fix Version/s: 1.1.2
  • Component/s: XML
  • Labels:
    None
  • Testcase included:
    yes
  • Number of attachments :
    6

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

  1. CastorState.java
    21/Sep/05 7:23 PM
    0.1 kB
    Benoit Xhenseval
  2. CastorTest.java
    21/Sep/05 7:23 PM
    2 kB
    Benoit Xhenseval
  3. castor-test.xml
    21/Sep/05 7:24 PM
    0.1 kB
    Benoit Xhenseval
  4. patch.c1221.20070515.txt
    15/May/07 10:20 AM
    3 kB
    Werner Guttmann
  5. patch.c1221.20070516.txt
    16/May/07 4:41 AM
    4 kB
    Werner Guttmann
  6. patch.c1221.20070516-002.txt
    16/May/07 5:33 AM
    7 kB
    Werner Guttmann

Issue Links

Activity

Hide
Brian Lee added a comment -

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.

Show
Brian Lee added a comment - 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.
Hide
Matt Griffin added a comment -

I've noticed that enums do marshal successfully if there is a mapping explicitly provided for the enum property. Using the auto-mapping or auto-complete feature results in the property being ignored when the object is marshalled.

Show
Matt Griffin added a comment - I've noticed that enums do marshal successfully if there is a mapping explicitly provided for the enum property. Using the auto-mapping or auto-complete feature results in the property being ignored when the object is marshalled.
Hide
Werner Guttmann added a comment -

Still, even though there's a work-around available, this should be looked into.

Show
Werner Guttmann added a comment - Still, even though there's a work-around available, this should be looked into.
Hide
Werner Guttmann added a comment -

First patch for review. For me this small patch makes the sam ple code work as expected.

Show
Werner Guttmann added a comment - First patch for review. For me this small patch makes the sam ple code work as expected.
Hide
Werner Guttmann added a comment -

Given the high number of votes, I now expect plenty of feedback ... .

Show
Werner Guttmann added a comment - Given the high number of votes, I now expect plenty of feedback ... .
Hide
Werner Guttmann added a comment -

Improved patch, that allows these code additions to be executed with Java versions 1.3 and 1.4.

Show
Werner Guttmann added a comment - Improved patch, that allows these code additions to be executed with Java versions 1.3 and 1.4.
Hide
Werner Guttmann added a comment -

Final patch for review.

Show
Werner Guttmann added a comment - Final patch for review.
Hide
Werner Guttmann added a comment -

Whilst this is ready to be committed, I'd rely on user feedback as I might not be able to anticipate all possible regression issues. In other words, if there's interest to see this committed as soon as possible (e.g. in time for 1.1.2 final), please test.

Show
Werner Guttmann added a comment - Whilst this is ready to be committed, I'd rely on user feedback as I might not be able to anticipate all possible regression issues. In other words, if there's interest to see this committed as soon as possible (e.g. in time for 1.1.2 final), please test.
Hide
Werner Guttmann added a comment -

Hmm, odd. Looks like (right now) I don't have the permissions to resolve this issue. Let me check again later, and if that does not change anything, go somewhere whinging .. .

Show
Werner Guttmann added a comment - Hmm, odd. Looks like (right now) I don't have the permissions to resolve this issue. Let me check again later, and if that does not change anything, go somewhere whinging .. .
Hide
Werner Guttmann added a comment -

It looks, though, as if there's a few more remaining issues related to unmarshalling Java 5 enums and no mapping file. But as long as there's a work-around, i.e. using a mapping file, this won't be on the top of my list.

Show
Werner Guttmann added a comment - It looks, though, as if there's a few more remaining issues related to unmarshalling Java 5 enums and no mapping file. But as long as there's a work-around, i.e. using a mapping file, this won't be on the top of my list.
Hide
Werner Guttmann added a comment -

Actually, it looks like the patch for CASTOR-991 actually resolves these remaining issues as described above. Will create a follow-up issue to resolve this anomaly..

Show
Werner Guttmann added a comment - Actually, it looks like the patch for CASTOR-991 actually resolves these remaining issues as described above. Will create a follow-up issue to resolve this anomaly..

People

Vote (4)
Watch (6)

Dates

  • Created:
    Updated:
    Resolved: