<structure name="enum">
<value name="name" style="attribute" field="itsEnum" deserializer="...Enum.find"/>
</structure>
You could also define a <format> for the Enum type, to make the deserializer use automatic.
- Dennis
Guillaume Pothier wrote:
Well this would require passing an IUnmarshallingContext to my Enum.find method wouldn't it? Which makes my application code dependant on JiBX.
Or, if I make the Enum.find method with one Object argument, would it pass it the value of the name attribute? I would have thought it would pass the Enum instance, which is the parent object.
In your example, where do I specify the field in which goes the Enum instance? in the <structure> or in the <value>?
Thanks for your help!
Guillaume
Dennis Sosnoski wrote:
If the Enum implements toString() with the appropriate text result you should be able to just say factory="...Enum.find" and use the Enum class directly. This would use a binding along the lines of:
<structure name="enum"> <value name="name" style="attribute" factory="...Enum.find"/> </structure>
If it *doesn't* implement toString() you can use a serializer/deserializer to get the same effect (with the find() method as the deserializer) - but it's cleaner to just implement the toString() method, since generally that's what you'd do anyway.
- Dennis
Guillaume Pothier wrote:
I have a class like this:
public class Enum
{
public static final Enum V1 = new Enum ("v1"); public static final Enum V2 = new Enum ("v2");
(...)
private String itsName;
private Enum (String aName) { itsName = aName; }
// Retrieves the corresponding instance public static Enum find (String aName) {...} }
I want to map it to <enum name="v1"/> for instance.
And I have class Foo: class Foo { private Enum itsEnum; }
that I want to map to: <foo> <enum name="v2"/> </foo>
A possibility would be to add an <enumeration> tag:
<mapping name="foo" class="Foo">
<enumeration name="enum" class="Enum" id-attribute="name" id-field="itsName" factory="find"/>
</mapping>
This specifies that the enum tag will be mapped to the Enum class, the marshalling process will put the value of the "itsName" field into the "name" tag, and the unmarshaller will use the "find" method giving it the content of the "name" attribute as an argument.
How does it sound? Guillaume
------------------------------------------------------- This SF.net email is sponsored by: The Robotic Monkeys at ThinkGeek For a limited time only, get FREE Ground shipping on all orders of $35 or more. Hurry up and shop folks, this offer expires April 30th! http://www.thinkgeek.com/freeshipping/?cpg=12297 _______________________________________________ jibx-users mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jibx-users
------------------------------------------------------- This SF.net email is sponsored by: The Robotic Monkeys at ThinkGeek For a limited time only, get FREE Ground shipping on all orders of $35 or more. Hurry up and shop folks, this offer expires April 30th! http://www.thinkgeek.com/freeshipping/?cpg=12297 _______________________________________________ jibx-users mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jibx-users
-- Dennis M. Sosnoski Enterprise Java, XML, and Web Services Training and Consulting http://www.sosnoski.com Redmond, WA 425.885.7197
------------------------------------------------------- This SF.net email is sponsored by: The Robotic Monkeys at ThinkGeek For a limited time only, get FREE Ground shipping on all orders of $35 or more. Hurry up and shop folks, this offer expires April 30th! http://www.thinkgeek.com/freeshipping/?cpg=12297 _______________________________________________ jibx-users mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jibx-users
