Is it possible to look up for existence of specified attributes in the Simple framework for java? Let's say I have the following xml:
<packet id="250">
<msg id="1" uniqueAttribute1="some value" x="7" />
<msg id="2" someStuff="123" />
<msg id="3" someOtherStuff="abc" />
</packet>
All the msgs above should be deserialized into objects of different classes perhaps inherited from a common base class. Which msg should instantiate an object of which class should depend on name of a attribute. Meaning if there in the msg exists attribute named 'uniqueAttribute' then an object of class Foo should be created, if there is 'someStuff' an object of class Bar and so on.
The only way which comes to my mind is to try to deserialize to objects of the classes and catching exceptions and retrying which sounds bad.
If it is not possible with the 'Simple' framework maybe you could suggest some other method?
There are a number of ways to do this. Typically a Visitor or Strategy can be used. See the following for how to use a Visitor. This uses a namespace to determine the type, but you could change this to use an attribute or a number of them.
Also, you could use a Converter to do this. Take a look at the tutorial.