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 14, 2009, at 7:58 PM, Marc Johnen wrote:
> Hello everyone,
>
> I wrote an extended class of a JAXB generated class.
> When just 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
>