[Simple-support] Handling deserialization exceptions
Brought to you by:
niallg
|
From: Митя Б. <dn...@gm...> - 2012-06-11 18:28:45
|
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
|