I'm trying to unmarshal an XML field to a Java5 Enum.
I'm using a GeneralizedFieldHandler to do this.

Unfortunatly, I'm getting the following error trying to unmarshall :
java.lang.IllegalArgumentException: No enum const class TaskType.S
at java.lang.Enum.valueOf(Enum.java:192)
at TaskType.valueOf(TaskType.java:1)
...

Here is the mapping.xml :
<class name="Task">
                <field name="type" type="TaskType" handler="TaskTypeHandler">
                          <bind-xml name="type" node="attribute" />
                </field>
</class>

Here is the xml data file :
<tache type="S">

  Here is Task.java :
public class Task {
        private TaskType type;
        public TaskType getType() {
                return type;
        }

        public void setType(TaskType pType) {
                type = pType;
          }
}

Here is TaskType.java :
public enum TaskType {
        SCHEDULED('S'), OPTIONAL('O'), PROVOKED('P');

        private char string;

        TaskType(char pChar) {
                  string = pChar;
        }

        public char getChar() {
                return string;
        }
}

And here is TaskTypeHandler :
public class TaskTypeHandler extends GeneralizedFieldHandler {

        public TaskTypeHandler() {
                super();
        }

        public Object convertUponGet(Object pValue) {
                return null;
        }

        public Object convertUponSet(Object pValue) {
                  String tString = (String) pValue;
                if (tString.equals("S")) {
                        return TaskType.SCHEDULED;
                  } else if (tString.equals("O")) {
                        return TaskType.OPTIONAL;
                } else if (tString.equals("P")) {
                        return TaskType.PROVOKED;
                  } else {
                        return null;
                }
        }

        public Class<TaskType> getFieldType() {
                return TaskType.class;
        }
}


It seems that Castor does not use the GeneralizedFieldHandler and uses
the default behaviour instead, that is calling TaskType.valueOf("S").

Am I something wrong ? Is there a way to bypass the default behaviour ?

Thanks,
Greg

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to