how to use a mapper?

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

how to use a mapper?

jmjg
hi,

I am trying to use HibernateCollectionConverter and
HibernateCollectionsMapper from jira. Im guessing I can register the
converter like other converters I have (sort of), I am using the
xstream facade:

Xstream xstream = new XStream(new Sun14ReflectionProvider(), new Dom4JDriver());
xstream.registerConverter(new
HibernateCollectionConverter(xstream.getConverterLookup()));
but I cannot see how to use the mapper...any idea?

Is there somewhere some doc I cannot find? Apart from the javadoc and
the samples, the two minute tutorial its ok for simple stuff, but not
for advanced usage I think.

thanks.
Reply | Threaded
Open this post in threaded view
|

Re: how to use a mapper?

Grégory Joseph
Javier,

On 17/01/06, javier muguruza <[hidden email]> wrote:

> hi,
>
> I am trying to use HibernateCollectionConverter and
> HibernateCollectionsMapper from jira. Im guessing I can register the
> converter like other converters I have (sort of), I am using the
> xstream facade:
>
> Xstream xstream = new XStream(new Sun14ReflectionProvider(), new Dom4JDriver());
> xstream.registerConverter(new
> HibernateCollectionConverter(xstream.getConverterLookup()));
> but I cannot see how to use the mapper...any idea?
>


A ClassMapper (which HibernateCollectionsMapper is) can be passed
through XStream's constructor.

HTH,

g
Reply | Threaded
Open this post in threaded view
|

Re: how to use a mapper?

jmjg
thanks, Gregory.

As HibernateCollectionsMapper expects a ClassMapper in its
constructor, and my xstream object its not created yet (Im creating
it, so I just cannot use xstream.getClassMapper()), I came up with:

xstream = new XStream(new Sun14ReflectionProvider(), new
HibernateCollectionsMapper(new DefaultMapper(
                Mail.class.getClassLoader())), new Dom4JDriver());


But I get an exception in that line:

01/17 18:28:44,328 (  Mutils.java:21) ERROR java.lang.NullPointerException
        at com.thoughtworks.xstream.XStream.alias(XStream.java:562)
        at com.thoughtworks.xstream.XStream.setupAliases(XStream.java:239)
        at com.thoughtworks.xstream.XStream.<init>(XStream.java:194)
        at com.thoughtworks.xstream.XStream.<init>(XStream.java:181)
        at com.galeon.xstream.XstreamUtil.initXstream(XstreamUtil.java:71)
        at com.galeon.xstream.XstreamUtil.getXStream(XstreamUtil.java:64)

any other idea?
javi

On 1/17/06, Grégory Joseph <[hidden email]> wrote:

> Javier,
>
> On 17/01/06, javier muguruza <[hidden email]> wrote:
> > hi,
> >
> > I am trying to use HibernateCollectionConverter and
> > HibernateCollectionsMapper from jira. Im guessing I can register the
> > converter like other converters I have (sort of), I am using the
> > xstream facade:
> >
> > Xstream xstream = new XStream(new Sun14ReflectionProvider(), new Dom4JDriver());
> > xstream.registerConverter(new
> > HibernateCollectionConverter(xstream.getConverterLookup()));
> > but I cannot see how to use the mapper...any idea?
> >
>
>
> A ClassMapper (which HibernateCollectionsMapper is) can be passed
> through XStream's constructor.
>
> HTH,
>
> g
>
Reply | Threaded
Open this post in threaded view
|

RE: how to use a mapper?

Jörg Schaible
In reply to this post by jmjg
Hi Javi,

javier muguruza wrote on Tuesday, January 17, 2006 6:34 PM:

> thanks, Gregory.
>
> As HibernateCollectionsMapper expects a ClassMapper in its
> constructor, and my xstream object its not created yet (Im creating
> it, so I just cannot use xstream.getClassMapper()), I came up with:
>
> xstream = new XStream(new Sun14ReflectionProvider(), new
> HibernateCollectionsMapper(new DefaultMapper(
>                 Mail.class.getClassLoader())), new Dom4JDriver());
>
>
> But I get an exception in that line:
>
> 01/17 18:28:44,328 (  Mutils.java:21) ERROR
> java.lang.NullPointerException
> at com.thoughtworks.xstream.XStream.alias(XStream.java:562) at
> com.thoughtworks.xstream.XStream.setupAliases(XStream.java:239)
> at com.thoughtworks.xstream.XStream.<init>(XStream.java:194)
> at com.thoughtworks.xstream.XStream.<init>(XStream.java:181) at
> com.galeon.xstream.XstreamUtil.initXstream(XstreamUtil.java:71) at
> com.galeon.xstream.XstreamUtil.getXStream(XstreamUtil.java:64)
>
> any other idea?

This is unfortunately a manifestation of http://jira.codehaus.org/browse/XSTR-250: The class mapper mechanism is target for refactoring of the next release, since currently you cannot easily manipulate the chain. One (bad) solution is currently to create a private copy of the XStream class - unfortunately.

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

Re: how to use a mapper?

jmjg
sorry Jörg, I dont completely get it, could you elaborate a little more? thanks

On 1/18/06, Jörg Schaible <[hidden email]> wrote:

> Hi Javi,
>
> javier muguruza wrote on Tuesday, January 17, 2006 6:34 PM:
>
> > thanks, Gregory.
> >
> > As HibernateCollectionsMapper expects a ClassMapper in its
> > constructor, and my xstream object its not created yet (Im creating
> > it, so I just cannot use xstream.getClassMapper()), I came up with:
> >
> > xstream = new XStream(new Sun14ReflectionProvider(), new
> > HibernateCollectionsMapper(new DefaultMapper(
> >                 Mail.class.getClassLoader())), new Dom4JDriver());
> >
> >
> > But I get an exception in that line:
> >
> > 01/17 18:28:44,328 (  Mutils.java:21) ERROR
> > java.lang.NullPointerException
> >       at com.thoughtworks.xstream.XStream.alias(XStream.java:562)     at
> > com.thoughtworks.xstream.XStream.setupAliases(XStream.java:239)
> >       at com.thoughtworks.xstream.XStream.<init>(XStream.java:194)
> >       at com.thoughtworks.xstream.XStream.<init>(XStream.java:181)    at
> > com.galeon.xstream.XstreamUtil.initXstream(XstreamUtil.java:71)       at
> > com.galeon.xstream.XstreamUtil.getXStream(XstreamUtil.java:64)
> >
> > any other idea?
>
> This is unfortunately a manifestation of http://jira.codehaus.org/browse/XSTR-250: The class mapper mechanism is target for refactoring of the next release, since currently you cannot easily manipulate the chain. One (bad) solution is currently to create a private copy of the XStream class - unfortunately.
>
> - Jörg
>
Reply | Threaded
Open this post in threaded view
|

Re: how to use a mapper?

Mauro Talevi
javier muguruza wrote:
> sorry Jörg, I dont completely get it, could you elaborate a little more? thanks
>

XStream uses a chain of wrapped ClassMappers which applies in succession.
ATM it is not possible to just replace one.
This is an issues scheduled for the next functionality release (ie 1.2).
What you could do in the meantime is modify your own private version of
XStream.java, which is a facade, and change the mapper in the method buildMapper().

Cheers

Reply | Threaded
Open this post in threaded view
|

Re: Re: how to use a mapper?

jmjg
ok, thats clear now, thanks guys.

On 1/18/06, Mauro Talevi <[hidden email]> wrote:

> javier muguruza wrote:
> > sorry Jörg, I dont completely get it, could you elaborate a little more? thanks
> >
>
> XStream uses a chain of wrapped ClassMappers which applies in succession.
> ATM it is not possible to just replace one.
> This is an issues scheduled for the next functionality release (ie 1.2).
> What you could do in the meantime is modify your own private version of
> XStream.java, which is a facade, and change the mapper in the method buildMapper().
>
> Cheers
>
>