Re: [Simple-support] How to handle an empty XML element, when using a Converter via "@Convert"
Brought to you by:
niallg
|
From: Niall G. - Y. <Nia...@yi...> - 2013-02-26 22:22:39
|
Looks like a bug to me, ill take a closer look at it. If it's a bug ill release a fix for it shortly.
-----Original Message-----
From: Timo Rumland [mailto:tim...@di...]
Sent: Wednesday, 27 February 2013 4:42 AM
To: sim...@li...
Subject: [Simple-support] How to handle an empty XML element, when using a Converter via "@Convert"
Hello,
I have the following situation: I'm using the @Convert annotation with my own converter implementation on a class field named "time".
When I now try to deserialize XML, which contains that "time" element but is empty like this:
----
<time></time>
----
my converter will be called and the SimpleXML framework throws an exception:
----
[...]
Caused by: java.lang.NullPointerException at org.simpleframework.xml.convert.Reference.getType(Reference.java:70)
----
This is because my Converter implementation returns "null", when the XML element is empty. As the javadoc for "Converter.read" tells, it is not allowed to return "null".
But now my question is, how should I handle the situation, where I use a Converter which is "confronted" with an empty XML element?
Looking at the Method
"org.simpleframework.xml.convert.AnnotationStrategy.read(Type,
NodeMap<InputNode>, Value)"
We can see the following code snipped:
----
if(converter != null) {
Object data = converter.read(parent);
if(value != null) {
value.setValue(data);
}
return new Reference(value, data);
}
----
This means, that if there is a @Converter defined, it gets called in any case, even if the value of that XML element is empty/null. But at the same time, Converter.read(...) should not return "null".
I think the "AnnotationStrategy" class should handle this situation, checking for an empty XML element, so the converter gets not called in that case.
So, what is the correct way to handle such a situation, or is it a "drawback" (maybe even a bug) of the "AnnotationStrategy" class?
Thanks a lot for your help!
Best Regards,
Timo
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb
_______________________________________________
Simple-support mailing list
Sim...@li...
https://lists.sourceforge.net/lists/listinfo/simple-support
|