Althouh I can very well marshal/unmarshal
typesafe-enum simple properties, I still cannot do it
for a collection (say a List) of instances of this
typesafe enum class.
Any help is welcome! Thanks.

Here is a simple test case that fails:

public class EColors { // a type safe enum

    private String name;

    private EColors(String name) {
        this.name = name;
    }

    public static final EColors RED = new
EColors("RED");
    public static final EColors BLUE = new
EColors("BLUE");
    public static final EColors GREEN = new
EColors("GREEN");

    public String toString() {
        return name;
    }

    public static EColors valueOf(String name) {
        if ("RED".equals(name)) return RED;
        if ("GREEN".equals(name)) return BLUE;
        if ("BLUE".equals(name)) return GREEN;
        return null;
    }
}

public class MyObject { // the object to (un)marshal

    private EColors color; // this works
    private List severalColors; // list of of EColor
instances

    public EColors getColor() {
        return color;
    }

    public void setColor(EColors color) {
        this.color = color;
    }

    public List getSeveralColors() {
        return severalColors;
    }

    public void setSeveralColors(List severalColors) {
        this.severalColors = severalColors;
    }
}

The mapping file:

<mapping>       
        <class name="test.EColors"
verify-constructable="false" auto-complete="true"/>
        <class name="test.MyObject">
                <field name="color" type="test.EColors"/>
                <!-- what follows does not work -->
                <field name="severalColors" collection="arraylist"
type="test.EColors"/>
        </class>
</mapping>

The object I marshal:

        MyObject mo = new MyObject();
        mo.setColor(EColors.BLUE);
        List severalColors = new ArrayList();
        severalColors.add(EColors.BLUE);
        severalColors.add(EColors.GREEN);
        mo.setSeveralColors(severalColors);


The output marshalled file (missing the content of my
collection):

<?xml version="1.0" encoding="UTF-8"?>
<my-object><color>BLUE</color><several-colors/><several-colors/></my-object>

=====
Emmanuel Chavane


                
__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!
http://promotions.yahoo.com/new_mail 



----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-user

Reply via email to