users@jersey.java.net

Need UriService object in XmlAdapter classes

From: Babu Naidu <pbnaidu_at_gmail.com>
Date: Thu, 4 Feb 2010 16:39:27 -0700

Hi,

I have IFoo interface that is being implemented by Foo and RFoo. The RFoo
class contains JAXB annotations and it is returned by resource classes. I
also have IFooXmlAdapter class that marshalls/unmarshalls IFoo and RFoo.
RFoo object also contains hypermedia (links) and I'll be creating instances
of it in the IFooXmlAdapter class, I need access to UriService (we have a
custom UriService injectable provider which injects custom UriService, which
works for resource and provider classes).

I was thinking that I could do the following, however they don't seem
feasible or clear to me.

1) I can set an instance of UriService as property in HttpContext in my
resource class and access it in IFooXmlAdapter by accessing HttpContext,
however I am not sure if it is feasible and how to do this.
2) Paul answered this question already with the following response, however
I am confused as to how to create UnMarshaller and Marshaller and whether it
works for both application/xml and application/json media types. Can anyone
please elaborate on how to accomplish or solve this problem? any pointers to
classes or articles or both is greatly appreciated.


Please let me know if you've any questions.

Thanks
Babu

=====================
Paul's response is here
http://markmail.org/search/?q=jersey+XmlAdapter#query:jersey%20XmlAdapter+page:2+mid:2j3j2zgvxntywgvk+state:results

I think it is possible to set adapter instances in the un/marshaller.

This means it should be possible to inject on those instances. You could use
a ContextResolver<Unmarshaller> and ContextResolver<Unmarshaller> to return
a Un/marsahller for the required JAXB type. The resolver instances can have
UriInfo injected on it, and this can be passed to the adapters.

public class XXXContextResolver<Unmarshaller> { public
XXXContextResolver(@Context UriInfo ui) { // initiate adapters ... }

... }

Paul.

========================