camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eugeniu <eugen...@hotmail.com>
Subject Re: Configure json to use jaxb annotations
Date Tue, 08 May 2012 14:41:05 GMT
Hi Christian

I used the jettison library shipped with the jaxrs implementation. 

Here you can find some more information:
http://jersey.java.net/nonav/documentation/latest/json.html

This is a link for the library: http://jettison.codehaus.org/Download

And this is a marshal method I used to create a json string from my
annotated JAXB java class:

    public void marshal(Exchange ex) throws JAXBException {
        Configuration conf = new Configuration();
        MappedNamespaceConvention mnc = new MappedNamespaceConvention(conf);
        Writer writer = new StringWriter();
        XMLStreamWriter xmlStreamWriter = new MappedXMLStreamWriter(mnc,
writer);
        Object obj = ex.getIn().getBody();
        JAXBContext jc = JAXBContext.newInstance(obj.getClass());
        Marshaller marshaller = jc.createMarshaller();
        marshaller.marshal(obj, xmlStreamWriter);
        String json = writer.toString();
        ex.getIn().setBody(json);
    }


--
View this message in context: http://camel.465427.n5.nabble.com/Configure-json-to-use-jaxb-annotations-tp5687484p5694966.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Mime
View raw message