Re: [Simple-support] How to handle an empty XML element, when using a Converter via "@Convert"
Brought to you by:
niallg
|
From: Timo R. <tim...@di...> - 2013-03-19 21:04:41
|
Hello Niall,
> 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.
> Sounds like a good idea
any progress on this? It would be really helpful in my current project. It
would be great if a "Converter" is allowed to return null (or a "Value"
instance with its "value" property to be null).
Thanks a lot!
Best Regards,
Timo
-----Ursprüngliche Nachricht-----
Von: Niall Gallagher [mailto:gal...@ya...]
Gesendet: Mittwoch, 27. Februar 2013 11:21
An: sim...@li...; Timo Rumland
Betreff: Re: [Simple-support] How to handle an empty XML element, when using
a Converter via "@Convert"
Sounds like a good idea
--- On Tue, 26/2/13, Timo Rumland <tim...@di...> wrote:
> From: Timo Rumland <tim...@di...>
> Subject: Re: [Simple-support] How to handle an empty XML element, when
using a Converter via "@Convert"
> To: sim...@li...
> Received: Tuesday, 26 February, 2013, 11:43 PM Hello Niall,
>
> > 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.
>
> thanks a lot for your answer!
>
> Now in my opinion, a Converter should be allowed to return null (or a
> "Value" instance with its "value" property to be null).
>
> I could imagine, that there are circumstances, where a special value
> in a XML tag must be converted to "null" in the target/deserialized
> object. So allowing a converter to convert to null would enhance the
> flexibility (you could write a converter which converts
> <time>null</null> to Java's 'null' in the deserialized object).
>
>
> Best Regards,
> Timo
>
>
> -----Ursprüngliche Nachricht-----
> Von: Niall Gallagher - Yieldbroker
> [mailto:Nia...@yi...]
>
> Gesendet: Dienstag, 26. Februar 2013 23:21
> An: Timo Rumland; sim...@li...
> Betreff: RE: [Simple-support] How to handle an empty XML element, when
> using a Converter via "@Convert"
>
> 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
>
>
> ----------------------------------------------------------------------
> -------- 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
>
|