dev@jersey.java.net

FW: [Jersey] jersey-json _at_Consume POST

From: Gallagher,Patrick <Patrick.Gallagher_at_Cerner.com>
Date: Wed, 28 Oct 2009 10:48:29 -0500

Thanks Paul and Jakup. This all works great and I'm now where I need to be with JSON support. Appreciate all the support and dialog!

 




________________________________



Content-type: text/plain; charset=utf-8

Date: Tue, 27 Oct 2009 16:48:51 +0100

From: Jakub Podlesak <Jakub.Podlesak_at_Sun.COM>

Subject: [Jersey] jersey-json @Consume POST

 

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

 

----------------------------------------------------------------------
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.