View Javadoc
1   package org.kuali.asr.handler;
2   
3   import org.apache.log4j.Logger;
4   import org.codehaus.jackson.map.ObjectMapper;
5   import org.kuali.ole.ncip.bo.OLERenewItemList;
6   
7   import javax.xml.bind.JAXBContext;
8   import javax.xml.bind.Marshaller;
9   import java.io.StringWriter;
10  
11  /**
12   * Created with IntelliJ IDEA.
13   * User: maheswarang
14   * Date: 12/9/13
15   * Time: 6:03 PM
16   * To change this template use File | Settings | File Templates.
17   */
18  public class ResponseHandler {
19  
20      private static final Logger LOG = Logger.getLogger(ResponseHandler.class);
21      public String  marshalObjectToXml(Object object){
22          String response=null;
23          try{
24              StringWriter writer = new StringWriter();
25              JAXBContext context = JAXBContext.newInstance(object.getClass());
26               Marshaller marshaller = context.createMarshaller();
27              marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
28              marshaller.marshal(object, writer);
29              response = writer.toString();
30          }catch (Exception e){
31              e.printStackTrace();
32          }
33          return response;
34      }
35  
36  
37    public String marshalObjectToJson(Object object){
38        ObjectMapper objectMapper = new ObjectMapper();
39        String jsonContent ="";
40        try {
41            jsonContent = objectMapper.writeValueAsString(object);
42        } catch (Exception e) {
43            e.printStackTrace();
44        }
45        return jsonContent;
46  
47    }
48  }