users@jersey.java.net

Re: [Jersey] How to use Jersey with an extended JAXB-class?

From: Marc Johnen <sun_at_johnen.biz>
Date: Thu, 15 Oct 2009 09:04:21 -0700 (PDT)

Hi Paul,

thank you for the answer. I didn't really understand how to
register the MyObjectFactoryExResolver, though.

Sorry for double posting, I didn't register befor my first post
and thought it didn't go through.

Greetings
Marc


Paul Sandoz wrote:
>
> H Marc,
>
> I replied to the email you sent yesterday:
>
> http://markmail.org/search/?q=list
> %3Anet.java.dev.jersey.users#query:list%3Anet.java.dev.jersey.users
> +page:2+mid:xzif4hirncjlhrtl+state:results
>
> How are you monitoring replies to the list?
>
> Note that for non-members of the list, as yourself, the emails are
> moderated (so as to avoid spam).
>
> Paul.
>
>
> Hi Marc,
>
> You can use a ContextResolver:
>
> https://jsr311.dev.java.net/nonav/javadoc/javax/ws/rs/ext/ContextResolver.html
>
> For example:
>
> @Provider public MyObjectFactoryExResolver implements
> ContextResolver<Unmarshaller> {
>
> private final JAXBContext c;
>
> public MyObjectFactoryExResolver() { c = //context with appropriate
> non-extended and extended types// }
>
> public Unmarshaller getContext(Class<?> type) { if //type is not
> recognized// return null;
>
> Unmarshaller u = c.createUnmarshaller(); if //extended type//
> u.setProperty("com.sun.xml.bind.ObjectFactory",new ObjectFactoryEx());
>
> return u; } }
>
> Register MyObjectFactoryExResolver just like you would register a root
> resource class (a class annotated with @Path).
>
> ContextResolvers are also supported for the types JAXBContext and
> Marshaller
>
> Paul.
>
> On Oct 15, 2009, at 2:00 PM, Marc Johnen wrote:
>
>> Hello everyone,
>>
>> I wrote an extended class of a JAXB generated class.
>> When using JAXB, I would tell it to use a different ObjectFactory
>> like this:
>>
>> Unmarshaller u = context.createUnmarshaller();
>> u.setProperty("com.sun.xml.bind.ObjectFactory",new ObjectFactoryEx());
>> PersonEx p = (PersonEx)u.unmarshal(new StringReader("<person />"));
>> (see https://jaxb.dev.java.net/guide/Adding_behaviors.html)
>>
>> Can I do something similar with Jersey? I can't find how.
>>
>> Thanks
>> Marc
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>
>

-- 
View this message in context: http://n2.nabble.com/How-to-use-Jersey-with-an-extended-JAXB-class-tp3828837p3830264.html
Sent from the Jersey mailing list archive at Nabble.com.