Hi Diego,
Diego Mota wrote at Mittwoch, 21. Oktober 2009 00:41:
> Hello!
>
> I´d like to convert XML to objects. But i want recover static final fields
> (or static fields only) of objects in XML files.
>
> How can i do this?
>
> Ex:
> public class ModelObject {
> public static final String pathDB;
>
>
> public static void main(String args[]) {
>
> XStream xstream = new XStream(new DomDriver());
> ModelObject obj = new ModelObject();
>
> try {
> FileInputStream arquivo = new FileInputStream(new
> File("C:\\config.xml"));
> xstream.fromXML(arquivo, obj); //will initialize the
> pathDB field arquivo.close();
>
> } catch (IOException e) {
> e.printStackTrace();
> }
>
> }
>
> }
XStream behaves like Java serialization, it does completely ignore static
members - simply because these objects are not part of the serialized
instance at all.
However, you can write a custom converter for your type - you're free to do
what you want in your implementation - even saving and restoring static
fields. Have a look at the converter tutorial, it's easy.
- Jörg
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email