On Apr 30, 2010, at 5:44 PM, ljnelson wrote:
> On Fri, Apr 30, 2010 at 10:20 AM, Paul Sandoz [via Jersey]
> <[hidden email]> wrote:
> > That is some hardcore JAXB usage!
>
> Generally when I have to do something hardcore, it means I've done
> something wrong. But when your resource classes return all sorts of
> interfaces and generic types, well, I don't see a choice. :-P
>
> I realized after putting the blog entry together that the coordination
> space for the JAXB context resolver and the
> MessageBodyWriter#writeTo() implementation doesn't have to be a
> ThreadLocal. It could be a HttpServletRequest attribute!
Yes, that is much better.
> So my final
> version actually injects the HttpServletRequest via @Context, and then
> writeTo() sets the type information in there as a request attribute,
> and the JAXBContextResolver pulls the type information from it. I
> realize here I'm making an assumption about the ordering--namely that
> writeTo happens before JAXB context resolution--but I think this is
> probably an unspoken requirement of the specification.
>
Correct, one cannot resolve until one knows the type to resolve to a
JAXBContext.
Paul.