0

I'm trying to create a controller for Spring MVC that will return a JSONP in Badgerfish format. My code currently creates the JSONP correctly using Jackson, but I do not know how to specify Badgerfish format. Assuming that callback is the name of the callback function and summary is my jaxb object, then my code is currently

ObjectMapper objectMapper = new ObjectMapper();
return objectMapper.writeValueAsString(new JSONPObject(callback,summary));

Is there any way to do this using Jackson or I have to use another framework? I have found an approach to generate Badgerfish using RestEasy, but only for JSON.

dchar
  • 1,665
  • 2
  • 19
  • 28

1 Answers1

0

I actually managed to solve this with Jettison (I did not find a way to do this with Jackson). The required code is

Marshaller marshaller = null;
Writer writer = new StringWriter();
AbstractXMLStreamWriter xmlStreamWriter = new BadgerFishXMLStreamWriter(writer);
try {
    marshaller = jaxbContextSummary.createMarshaller();
    marshaller.marshal(myObject, xmlStreamWriter);
} catch (JAXBException e) {
    logger.error("Could not construct JSONP response", e);
}
dchar
  • 1,665
  • 2
  • 19
  • 28