Re: [Simple-support] Handling deserialization exceptions
Brought to you by:
niallg
|
From: Niall G. <gal...@ya...> - 2012-06-11 23:05:56
|
the order attribute must have required=false, take a look at the @Validate annotation, you can simply remove any orders that have a null id.
--- On Mon, 11/6/12, Митя Балахонский <dn...@gm...> wrote:
From: Митя Балахонский <dn...@gm...>
Subject: [Simple-support] Handling deserialization exceptions
To: sim...@li...
Received: Monday, 11 June, 2012, 11:28 AM
Hello, dear All
I'm very happy that such a thing as Simple Framework exists, it helps
me a lot :)
But now I have an issue:
I'm using XML for client-server data exchange, and server doesn't
always send me valid data.
For example:
<response>
<order id="123">
<name>Foo</name>
</order>
<order>
<name>Bar</name>
</order>
<order id="456">
<name>Alice</name>
</order>
</response>
I have a simple class for it:
@Root(name="order")
class Order {
@Attribute(name="id", required=true)
int id;
@Element(name="name", required=false)
String name;
}
@Root(name="response")
class Response {
@ElementList
List<Order> orders;
}
And an @ElementList of Order in the Response class.
It works perfectly until server sends me some order without the "id"
attribute. In this case parsing fails and I have no way to receive
other orders that were correctly formed, because framework exception
fires and cancels all the parsing.
Is there a proper way to handle it with Simple Framework?
I'd like to have a list of orders, which were parsed correctly, and
ignore incorrect ones. With my example that would be a list, containing Foo and
Alice, maybe having some notifications that 1 order cannot be parsed
because of the exception.
Thanks in advance!
--
Best regards,
Dmitry Balakhonsky
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Simple-support mailing list
Sim...@li...
https://lists.sourceforge.net/lists/listinfo/simple-support
|