Hi Francesco,
Francesco Pace wrote:
> Hi guys,
>
> I'm a newbie of XStream.
> I would to deserialize this file XML to test xstream annotations:
>
> <my last_modified="17/01/2012 16:19">
> </my>
>
> My.java class is:
>
> @XStreamAlias("my")
> public class My{
>
> @XStreamAlias("last_modified")
> @XStreamAsAttribute
> private String last_modified;
>
> public My() {
> this.last_modified = "--";
> }
> public String getLast_modified() {
> return last_modified;
> }
>
> public void setLast_modified(String last_modified) {
> this.last_modified = last_modified;
> }
> }
>
> I invoke with:
>
> String path = "C:\\Desktop\\xml.xml";
> InputStream inputStream = null;
> Reader reader = null;
>
> try {
> inputStream = new java.io.FileInputStream(new File(path));
> reader = new InputStreamReader(inputStream,
> Charset.forName("UTF-8"));
> }
> catch(Exception e){
> e.printStackTrace();
> }
> XStream xstream = new XStream(new StaxDriver());
> xstream.processAnnotations(My.class);
> My my= (My)xstream.fromXML(reader);
>
> Can you help me?
Write an instance to XML and you'll see immediately, why the attribute is
not read.
After that, look here:
http://xstream.codehaus.org/faq.html#XML_double_underscores
Cheers,
Jörg
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email