dev@jersey.java.net

Re: [Jersey] jersey-json _at_Consume POST

From: Jakub Podlesak <Jakub.Podlesak_at_Sun.COM>
Date: Tue, 27 Oct 2009 16:48:51 +0100

On Tue, Oct 27, 2009 at 04:17:07PM +0100, Paul Sandoz wrote:
>
> On Oct 27, 2009, at 3:50 PM, Gallagher,Patrick wrote:
>
> >Thanks Paul. I have also come across another issue while working
> >through this one. I created an issue [1] that illustrates this.
> >I’m responding on this thread due to the issue coming to life while
> >troubleshooting my initial problem and for completeness.
> >
> >1. https://jersey.dev.java.net/issues/show_bug.cgi?id=400
> >
>
> Thanks. Jakub can confirm but i think you will need to add a
> ContextResolver for namespaces support.
>
> For example, create the following class:
>
> @Provider
> public static class Resolver implements
> ContextResolver<JAXBContext> {
> private final JSONJAXBContext context;
>
> public Resolver() throws Exception {
> this.context = new
> JSONJAXBContext(JSONConfiguration.natural().build(), "json.junit");
> }
>
> public JAXBContext getContext(Class<?> type) {
> if (type == ReqType.class) {
> return context;
> }
>
> return null;
> }
> }
>
>
> make sure it is registered on the server side and also register it on
> the client side:
>
> ClientConfig cc = new DefaultClientConfig();
> cc.getClasses().add(Resolver.class);
> Client c = Client.create(cc);
>
> and then your test will pass.
>
> The above uses the JSON JAXB "natural" convention.
>
> By default Jersey uses it's mapped convention and i think when
> namespaces are required with the mapped convention you need to provide
> a mapping:

All above correct, only the mapped jersey notation namespaces config is here
(what Paul sent was for Jettison's mapped notation, not a big difference actually):
https://jersey.dev.java.net/nonav/documentation/1.1.2-ea/user-guide.html#d4e575

i.e. in your case you need st. like:

Map<String,String> ns2json = new HashMap<String, String>();
         ns2json.put("http://www.cerner.com/ipsvc/artifact/rest", "myns");
         context = new JSONJAXBContext(
         JSONConfiguration.mapped()
              .xml2JsonNs(ns2json).build(), types);

and then myns will be visible also in JSON, while by using the natural
notation the namespace usage will be fully transparent to JSON,

I am going to close the issue as invalid, but please feel free to reopen
if you think otherwise.

Thanks,

~Jakub

>
> https://jersey.dev.java.net/nonav/documentation/1.1.2-ea/user-guide.html
> #json.jaxb.jettison.mapped.ns.def
>
> Paul.
>
> >
> >
> >Content-type: multipart/alternative;
> > boundary="Boundary_(ID_2r55hb9wHFNXc7TIcUUnzQ)"
> >Date: Mon, 26 Oct 2009 16:26:22 +0100
> >From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
> >Subject: [Jersey] jersey-json @Consume POST
> >
> >On Oct 26, 2009, at 4:23 PM, Paul Sandoz wrote:
> >>
> >> OK. I suspect that because it was annotated with @XmlRootElement and
> >> @XmlType the old JSON/JAXB stuff got confused.
> >
> >
> >> In any case we should add a test case for this even though it is not
> >> working so we do not regress
> >> in the future.
> >
> >I mean to say "even though it is working...".
> >
> >Paul
> >
> >
> >CONFIDENTIALITY NOTICE This message and any included attachments are
> >from Cerner Corporation and are intended only for the addressee. The
> >information contained in this message is confidential and may
> >constitute inside or non-public information under international,
> >federal, or state securities laws. Unauthorized forwarding,
> >printing, copying, distribution, or use of such information is
> >strictly prohibited and may be unlawful. If you are not the
> >addressee, please promptly delete this message and notify the sender
> >of the delivery error by e-mail or you may call Cerner's corporate
> >offices in Kansas City, Missouri, U.S.A at (+1) (816)221-1024.
>

-- 
Jakub Podlešák
Software Engineer at SUN Microsystems And CZJUG Co-Leader
http://blogs.sun.com/japod