Topic
IC4NOTICE: developerWorks Community will be offline May 29-30, 2015 while we upgrade to the latest version of IBM Connections. For more information, read our upgrade FAQ.
No replies
RArnold
RArnold
1 Post
ACCEPTED ANSWER

Pinned topic Marshalling JSON inside a Liberty Profile OSGi bundle

‏2014-01-13T11:49:48Z |

In Liberty 8.5.5.0, is there any way to configure the JAXB marshaller to use JSON (in the context of a pure OSGi bundle)?

I am writing an OSGi service that itself consumes a JSON-based REST API. I'd like to try and use JAXB annotated classes and manually marshal/unmarshal the JSON. This works OK for XML, but I can't find a way to ask for JSON. Eclipselink uses the "eclipselink.media-type" property to achieve this. Is there a way do this with WLP855 out-of-the-box?

Something like this:

            JAXBContext context = JAXBContext.newInstance(MyBean.class);
            Marshaller m = context.createMarshaller();
            m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
            m.setProperty(PROP_MEDIA_TYPE, MediaType.APPLICATION_JSON);
            m.setProperty(PROP_INCLUDE_ROOT, false);
            m.marshal(myBeanValue, writer);


would be nice.

I've also tried using the Jackson ObjectMapper which is present in the jaxrs jar under dev/api/third-party - but it appears this only works in an EE context - whereas what I'm looking for us something usable inside an OSGi bundle.

Many thanks...