Hello Pavel, I'll try to put together a test case (would be tough, given my
time constraints), but I will create an issue
though.
Moxy (2.2.0) actually chokes completely, here is what I get for different
JSON configuration:
* badgerFish -> nada (nothing)
* natural -> null (strange)
* mapped -> nada (nothing)
Actually, this is turning out to be a nightmare for us :), need to use some
Moxy features.
JAXB-RI (metro) means we have to make changes but the more severe problem is
this, our
restrictions are:
* We cannot change the JDK install (so cannot e.g. drop JAXB 2.2 -API) via
endorsed mechanisms.
* The production servers do *not* allow system properties to be set, so
can't drop the JAXB 2.2-API
jersey-json has transitive dependencies to JAXB 2.2 both impl and API.
Currently I am excluding that (although
I have heard that the JAXB 2.2 Impl (RI) automatically switches to 2.1 IMPL
if it finds JAXB 2.1 API (we run
JDK6 18). So one option we are seriously considering is to ditch Moxy for
now (time constraints) and use the
Sun JAXB impl probably 2.1.13.
Unfortunately, in an enterprise environments, you don;t have a lot of
flexiblility in changing the system environment,
the current JDK 6 and JAXB RI (metro impl) annoyance is becoming a major
pain for us :(.
Thanks!
Regards,
Mohan KR
From: Pavel Bucek [mailto:pavel.bucek_at_oracle.com]
Sent: Friday, April 22, 2011 10:11 AM
To: users_at_jersey.java.net
Subject: [Jersey] Re: (Updated Possible issue) RE: CustomResolver
(Marshaller) dual content type xml and json
Pretty interesting. That is definitely a bug, can you please file new issue
in our issue tracker? Ideally with testcase..
Just out of curiosity - can you try the same thing with Moxy implementation?
It would be good to know that the issue is not in JAXB implementation but in
jersey-json module.
Thanks!
Pavel
On 4/22/11 4:56 PM, Mohan KR (mkannapa) wrote:
Maybe it will help someone, but I was able to get the below to work, by
disable the formatted output marshaller
property (i.e. false). So, I am not sure why the JSON marshaller's are
sensitive to the formatting, don't know whether
it should be raised as a bug or that the JSON marshaller expects no
formatting, especially when fragment is turned on.
Thanks!
Regards,
Mohan KR
From: Mohan KR (mkannapa) [mailto:mkannapa_at_gmail.com]
Sent: Friday, April 22, 2011 7:44 AM
To: users_at_jersey.java.net
Subject: RE: CustomResolver (Marshaller) dual content type xml and json
*bump*
Apologize for bumping it, seeing if anyone had experience this? Some more
details here is my CustomResolver. A few things
I have tried:
* Different JAXB impl : a) The one bundled with JDK1.6 b) Metro JAXB
2.1.13 c) Moxy 2.2.0
It does not matter, JSON is not being generated, and there are no logs that
i could see to tell where I'm going wrong.
If this is not the correct approach would appreciate any pointers in the
right direction.
@Provider
public class ContextResolverMarshaller
implements ContextResolver<Marshaller> {
@Override
public Marshaller getContext(Class<?> type) {
if (type == null) {
return null;
}
//We will create the JSONJaxbContext, so we can support both XML and
JSON
JSONJAXBContext ctxt = null;
// create a brand spanking new one, note I have tried all the
different JSON
// configurations, to no avail
try {
ctxt = new
JSONJAXBContext(JSONConfiguration.badgerFish().build(), type);
}
catch (final JAXBException ex) {
return ctxt;
}
Marshaller m = null;
try {
m = ctxt.createMarshaller();
}
catch (final JAXBException ex) {
return m;
}
// set our properties
this.setProperty(m, Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
this.setProperty(m, Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
return m;
}
private void setProperty(Marshaller m, String name, Object value) {
try {
m.setProperty(name, value);
}
catch (final PropertyException ex) {
//log
}
}
}
Thanks!
Regards,
Mohan KR
From: Mohan KR (mkannapa) [mailto:mkannapa_at_gmail.com]
Sent: Wednesday, April 20, 2011 7:19 PM
To: users_at_jersey.java.net
Subject: CustomResolver (Marshaller) dual content type xml and json
Greetings,
My core problem is I need to support XML and JSON in my responses. I have
JAXB annotated POJOS, and
my resource method's have the appropriate @Produces Annotation. With this
setup everything appears
to be working fine, using curl to send separate requests with the
appropriate Accept headers.
After, making sure things were working, I need to set some Marshaller
Properties, and it appears that the
recommended approach is to use the ContextResolver<Marshaller> approach. I
did that and registered it
as a provider to the runtime. Now, XML content type is working fine, but
JSON is broken I get no content.
Do I need to implement a JSONMarshaller too? Although my ContextResolver
is being called when I make
the request with application/xml and application/json. Don't know whether
it is a bug or maybe I'm missing
something.
I'm using jersey 1.6. Thanks in advance.
Thanks!
Regards,
Mohan KR