Question

I am experimenting with the Simple XML framework to process XML files on Android. However, what's really starting to puzzle me is, how this library actually creates and populates the objects during XML parsing/deserialization. For test purposes I have declared a specific class' constructor as well as all attributes as private, so it should be impossible for any other class to create such an object nor should it be able to populate its fields. Only the provided setter methods are public.

But Simple XML somehow manages to not only create but also to populate these objects and completely ignores the setter methods!

This is a pity, because some of the setter methods were supposed to have some side effect (namely registering the object in a hash-table keyed by the passed-in value for later quicker lookup by value). But without the setter method being called that approach of course doesn't fly.

So, how does SimpleXML manage to bypass this?

Was it helpful?

Solution

Simple uses reflections to to read / write objects. Hoewever, you can customize it's operations.

You can try @Default(DefaultType.PROPERTY) annotation on your class, this will use the naming conventions of java beans.

If everything fails, you always can implement the (de-)serialization by your own, using a Converter.

Please check those links:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top