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
13
14
15
16
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 System.out.println(objectMapper.writeValueAsString(object));
43
44 } catch (Exception e) {
45 e.printStackTrace();
46 }
47 return jsonContent;
48
49 }
50
51 }