001package org.kuali.asr.handler;
002
003import org.apache.log4j.Logger;
004import org.codehaus.jackson.map.ObjectMapper;
005import org.kuali.ole.ncip.bo.OLERenewItemList;
006
007import javax.xml.bind.JAXBContext;
008import javax.xml.bind.Marshaller;
009import java.io.StringWriter;
010
011/**
012 * Created with IntelliJ IDEA.
013 * User: maheswarang
014 * Date: 12/9/13
015 * Time: 6:03 PM
016 * To change this template use File | Settings | File Templates.
017 */
018public class ResponseHandler {
019
020    private static final Logger LOG = Logger.getLogger(ResponseHandler.class);
021    public String  marshalObjectToXml(Object object){
022        String response=null;
023        try{
024            StringWriter writer = new StringWriter();
025            JAXBContext context = JAXBContext.newInstance(object.getClass());
026             Marshaller marshaller = context.createMarshaller();
027            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
028            marshaller.marshal(object, writer);
029            response = writer.toString();
030        }catch (Exception e){
031            e.printStackTrace();
032        }
033        return response;
034    }
035
036
037  public String marshalObjectToJson(Object object){
038      ObjectMapper objectMapper = new ObjectMapper();
039      String jsonContent ="";
040      try {
041          jsonContent = objectMapper.writeValueAsString(object);
042      } catch (Exception e) {
043          e.printStackTrace();
044      }
045      return jsonContent;
046
047  }
048}