Alexander,

This isn't something easily done in Castor. I've done this myself in the past using a dynamic FieldDescriptor approach, basically you need to override the XMLClassDescriptor#getFieldDescriptor method such that it creates an XMLFieldDescriptor using the passed in xml name, or returns a cached one based on the given name.

I don't have time to provide more details at the moment, but if you're feeling brave you may want to start looking into that approach. If you're having trouble with this, I'll see if I can dig up the code I wrote a while back and provide a more concrete example for you when I get some free time.

--Keith

Alexander Papaspyrou wrote:
Hi,

after staring at the Castor documentation and FAQ for a couple of hours without finding an answer (or a hint, at least), I decided to ask on the mailing list whether the following is possible:

I have a rather generic class "Attribute", consisting of a key (the name of the Attribute) and subclasses which add a value (the "content" of the Attribute); in Java this looks something like

public class Attribute {
    private String key;
}

public class StringAttribute {
    private String value;
}

Assuming that, for an instance of StringAttribute, I have key="foo" and value="bar", I'd like to map this to XML looking like

<foo>bar</foo>

Can this be done with Castor (or <insert mapping tool here>)? I'll happily write some custom code to do it, as long as I don't have to create DOM documents from scratch.

Regards,
Alexander Papaspyrou





Reply via email to