Newbie question...

View: New views
5 Messages — Rating Filter:   Alert me  

Newbie question...

by Vasanth Loka :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I am having trouble creating this xml with a single line:

<person age="9999">Vasanth Loka</person>

Need help.


Re: Newbie question...

by Andreas Zeller-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Vasanth,

(Jörg: You should probably put this into the FAQ :) )

I came across the same problem a few years back. XStream can't produce this XML without a custom converter.

There is a nice tutorial that deals with converters on http://xstream.codehaus.org/

If you're too lazy to do that, check out: http://markmail.org/message/tsxysxbm5fyvadif

That'll help.
--
Andreas Zeller

Geschäftsleitung
lux-medien.com
Kortumstr.78
47057 Duisburg

Tel : +49 203 9 311 609
Fax : +49 203 9 311 610
Mobil: +49 163 27 9 1979


Vasanth Loka wrote:
I am having trouble creating this xml with a single line:

<person age="9999">Vasanth Loka</person>

Need help.


  

Re: Newbie question...

by Vasanth Loka :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Thanks Andreas for your response. I went through various old posts and saw that I have to create a custom convertor. I did. But still having trouble. Probably, I am overlooking something pretty straightforward..
The error I am getting is:
com.thoughtworks.xstream.converters.ConversionException: null : null
---- Debugging information ----
cause-exception     : java.lang.RuntimeException
cause-message       : null
class               : com.xstream.model.Person
required-type       : com.xstream.model.Fullname
path                : /person/fullname
line number         : 4
-------------------------------

I have created a test project with minimal required classes to reproduce the problem and am attaching the project. I am at a loss. Any help is appreciated.

Andreas Zeller-4 wrote:
Hi Vasanth,

(Jörg: You should probably put this into the FAQ :) )

I came across the same problem a few years back. XStream can't produce
this XML without a custom converter.

There is a nice tutorial that deals with converters on
http://xstream.codehaus.org/

If you're too lazy to do that, check out:
http://markmail.org/message/tsxysxbm5fyvadif

That'll help.
--
*Andreas Zeller*

Geschäftsleitung
lux-medien.com <http://www.lux-medien.com/>
Kortumstr.78
47057 Duisburg

Tel : +49 203 9 311 609
Fax : +49 203 9 311 610
Mobil: +49 163 27 9 1979


Vasanth Loka wrote:
> I am having trouble creating this xml with a single line:
>
> <person age="9999">Vasanth Loka</person>
>
> Need help.
>
>
>  
ZXStreamTest.zip

Re: Newbie question...

by Andreas Zeller-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

That is why I attached example code of a custom (existing and working) converter of mine :)

Judging by the debugging info, it looks like you want to deal with a "Fullname" class, but what you're actually having is a "Person" class.

From your previous example it seemed more like "Fullname" was a String inside the Person class?

So. If I get you right:

You have a class "Person", Including String "fullname" and Integer "age", simple POJO, right?

And you want this result:

<person age="9999">Vasanth Loka</person>
So you want a custom converter. You read the nested value via getValue() on the streamReader, insert it into "fullname" of your POJO. Next, you want the age value. Read the attribute "age" via streamReaderObj.getAttribute("age"); and set it to the "age" value of your POJO. That's it for unmarshaling.

Now for the marshaling part:

Skip the 'startNode("person");' because you want to write a nested value directly. So, use addAttribute("age"); , write the Integer Value "age" of your POJO into the person tag. Then, setValue("Vasanth Loka"); and be happy.

That's pretty much it. Try the tutorials. All you need to do, is read/write.

Give it another shot. Good night.

--
Andreas Zeller

Geschäftsleitung
lux-medien.com
Kortumstr.78
47057 Duisburg

Tel : +49 203 9 311 609
Fax : +49 203 9 311 610
Mobil: +49 163 27 9 1979


Vasanth Loka wrote:
Thanks Andreas for your response. I went through various old posts and saw
that I have to create a custom convertor. I did. But still having trouble.
Probably, I am overlooking something pretty straightforward..
The error I am getting is:
com.thoughtworks.xstream.converters.ConversionException: null : null
---- Debugging information ----
cause-exception     : java.lang.RuntimeException
cause-message       : null
class               : com.xstream.model.Person
required-type       : com.xstream.model.Fullname
path                : /person/fullname
line number         : 4
-------------------------------

I have created a test project with minimal required classes to reproduce the
problem and am attaching the project. I am at a loss. Any help is
appreciated.


Andreas Zeller-4 wrote:
  
Hi Vasanth,

(Jörg: You should probably put this into the FAQ :) )

I came across the same problem a few years back. XStream can't produce
this XML without a custom converter.

There is a nice tutorial that deals with converters on
http://xstream.codehaus.org/

If you're too lazy to do that, check out:
http://markmail.org/message/tsxysxbm5fyvadif

That'll help.
-- 
*Andreas Zeller*

Geschäftsleitung
lux-medien.com <http://www.lux-medien.com/>
Kortumstr.78
47057 Duisburg

Tel : +49 203 9 311 609
Fax : +49 203 9 311 610
Mobil: +49 163 27 9 1979


Vasanth Loka wrote:
    
I am having trouble creating this xml with a single line:

<person age="9999">Vasanth Loka</person>

Need help.


  
      
    
http://www.nabble.com/file/p25428971/ZXStreamTest.zip ZXStreamTest.zip 
  

Re: Newbie question...

by Jörg Schaible-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Andreas Zeller wrote at Sonntag, 13. September 2009 16:58:

> Hi Vasanth,
>
> (Jörg: You should probably put this into the FAQ :) )

Yeah, seems so really. :)

Thanks for chiming in.

- Jörg


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email