I have been trying to write a custom field handler which returns the hash code of a java.awt.Image object when writing to XML and retrieves an image based on this hash code when binding the XML to an object. For some reason, I can't get this to work; castor, from what I can tell, simply instantiates the field handler and then doesn't call any of its methods.
Can you give me a quick example of how to do this because I must be missing something simple!
Cheers,
Pete
Pasting your code can be a good idea. Anyway following works fine for me
<m:class name="someClass">
<m:map-to xml="class"/>
<m:field name="lineColor" type="java.awt.Color" handler="ColorFieldHandler">
<m:bind-xml name="lineColor" node="attribute"/>
</m:field>
</m:class>
And the handler itself
public class ColorFieldHandler extends GeneralizedFieldHandler {
public Object convertUponGet(Object value) {
if (value == null) {
return null;
}
Integer colorHash = (Integer) value;
...
Hope that helps
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.