converters tutorial

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

converters tutorial

falcorn

Hi.
Is any tutorial about writing own converters?
Greetings

----------------------------------------------------------------------
Kliknij po wiecej! >>> http://link.interia.pl/f18ed

Reply | Threaded
Open this post in threaded view
|

RE: converters tutorial

Jörg Schaible

Hi Piotr,

Piotr Idzikowski wrote on Monday, February 20, 2006 2:22 PM:

> Hi.
> Is any tutorial about writing own converters?

Not published on the site, but already available in Subversion:
http://svn.xstream.codehaus.org/*checkout*/trunk/xstream-website/src/content/converter-tutorial.html?rev=673

- Jörg
Reply | Threaded
Open this post in threaded view
|

Re: converters tutorial

falcorn
Hi. Thanks for answer.
But I want more.
Is somewere more about?
Where can I read something about UnmarshalingContext and methods:
ConvertAnother
Greetings
Reply | Threaded
Open this post in threaded view
|

Re: converters tutorial

Jörg Schaible-2
Hi Piotr,

Piotr Idzikowski wrote:

> Hi. Thanks for answer.
> But I want more.
> Is somewere more about?
> Where can I read something about UnmarshalingContext and methods:
> ConvertAnother
> Greetings

Unfortunately none have been written yet. You should take a look at the
source of the Converters in c.t.x.converter and below ...

http://svn.xstream.codehaus.org/trunk/xstream/src/java/com/thoughtworks/xstream/converters/

- Jörg



Reply | Threaded
Open this post in threaded view
|

Re: CDATA

falcorn
In reply to this post by Jörg Schaible
 >Jörg Schaible wrote:
 >
 >> Hi Carlo,
 >>
 >> Dapor, Carlo wrote:
 >>
 >> [snip]
 >>
 >>> See my defect under http://jira.codehaus.org/browse/XSTR-271
 >>
 >> Thanks for your effort. We will have a look at the issue.
 >
 >Hi Carlo,
 >
 >you should have been done with:
 >
 >XStream xstream = new XStream(
 >    new XppDriver() {
 >        public HierarchicalStreamWriter createWriter(Writer out) {
 >            return new PrettyPrintWriter(out) {
 >                protected void writeText(QuickWriter writer, String
 >text) {
 >                    writer.write("<[CDATA[");
 >                    writer.write(text);
 >                    writer.write("]]>");
 >                }
 >            }
 >        }
 >    }
 >);
 >
 >- Jörg

Hi. I is nice.
But for example i have this class:
class A{
  ClassB field1;
  ClassC field2;
}

class classB {
        String wantSrtingWithCDATA;
}

class classC {
        String dontWantClassWithCDATA;
}

Class classB must be serialize with CDATA and no changes at text but
classC no, and all escape sequences has to be changed.

What should I do?
I've tried to change Writer at marshall class, but I don't know how to
do it.
Thanks
Greetings
Piotr

------------------------------------------------------------------
Jestes poszukiwana. Szuka Cie wysoki brunet!
>> http://link.interia.pl/f190c <<

Reply | Threaded
Open this post in threaded view
|

Re: CDATA

Jörg Schaible-2
Hi Piotr,

Piotr Idzikowski wrote:

[snip]

>
> Hi. I is nice.
> But for example i have this class:
> class A{
>   ClassB field1;
>   ClassC field2;
> }
>
> class classB {
> String wantSrtingWithCDATA;
> }
>
> class classC {
> String dontWantClassWithCDATA;
> }
>
> Class classB must be serialize with CDATA and no changes at text but
> classC no, and all escape sequences has to be changed.
>
> What should I do?
> I've tried to change Writer at marshall class, but I don't know how to
> do it.

In this case you must use the default implementation of writeText if it is
none of your special classes. You can save the name of the tag in startNode
on a stack and check the top element of the stack in writeText.
PrettyPrintWriter already does something like that, but the stack is privat
and therefore no accessible. In this case I would simply copy the source of
the class, modify it and use it with a different name e.g.
CDATAAwarePrettyPrintDriver.

- Jörg

Reply | Threaded
Open this post in threaded view
|

Re: Re: CDATA

falcorn
Jörg Schaible napisał(a):

> In this case you must use the default implementation of writeText if it is
> none of your special classes. You can save the name of the tag in startNode
> on a stack and check the top element of the stack in writeText.
> PrettyPrintWriter already does something like that, but the stack is privat
> and therefore no accessible. In this case I would simply copy the source of
> the class, modify it and use it with a different name e.g.
> CDATAAwarePrettyPrintDriver.
>
> - Jörg
>  
Hi. Thanks for help. I've make it and it's work fine.
But maybe it would be nice to add new method to HierarchicalStreamWriter
interface; something like setCdataValue().
Greetings