users@jersey.java.net

Re: [Jersey] Custom IDResolver

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Fri, 31 Oct 2008 08:45:54 +0100

Hi,

You need to use a ContextResolver either ContextResolver<JAXBContext>
or ContextResolver<Unmarshaller>.

In your case i think the latter:

   @Provider
   public class IDContextResolver implements
ContextResolver<Unmarshaller> {
       public Unmarshaller getContext(Class<?> type) {
           if (type != ...) return null;

           Unmarshaller u =context.createUnmarshaller();
           u.setProperty(IDResolver.class.getName(),new MyIDResolver());
           return u;
       }
   }

Paul.

On Oct 31, 2008, at 12:24 AM, sarat.pediredla wrote:

>
> I have a very simple problem using Jersey but I cannot for the life
> of me
> figure out how to do this in a pluggable manner without defining our
> own
> custom @Provider for Unmarshalling.
>
> Basically I have a class with a XmlIDRef to the XmlID of an associated
> class. However, since the XML is using a Ref and not the entire XML
> map,
> when someone does a PUT, the relationship gets destroyed.
>
> Sample XML produced
>
> <note>
> <id>2</id>
> <subject>asdf asdfa sdfa sdf</subject>
> <created-at>2008-10-30T22:26:42.185Z</created-at>
> <created-by>1</created-by> <---------- This is a XmlIDRef to a User
> object
> </note>
>
> Now when I do a PUT, the createdBy is not automatically mapped to the
> external User object (obviously).
>
> Is there an easy way to define a custom IDResolver in Jersey without
> having
> to write by own MessageBodyReader?
>
> --
> View this message in context: http://n2.nabble.com/Custom-IDResolver-tp1400907p1400907.html
> Sent from the Jersey mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>