1 package com.atlassian.plugins.rest.common.json;
2
3 import org.codehaus.jackson.JsonEncoding;
4 import org.codehaus.jackson.map.Module;
5
6 import javax.ws.rs.core.MediaType;
7 import javax.xml.bind.JAXBException;
8 import java.io.ByteArrayOutputStream;
9 import java.io.IOException;
10 import java.util.Collections;
11
12 public class DefaultJaxbJsonMarshaller implements JaxbJsonMarshaller
13 {
14 public String marshal(Object jaxbBean)
15 {
16 try
17 {
18 final ByteArrayOutputStream os = new ByteArrayOutputStream();
19
20
21 new JacksonJsonProviderFactory().create(Collections.<Module>emptyList()).writeTo(jaxbBean, jaxbBean.getClass(), null, null, MediaType.APPLICATION_JSON_TYPE, null, os);
22
23 return new String(os.toByteArray(), JsonEncoding.UTF8.getJavaName());
24 }
25 catch (IOException e)
26 {
27 throw new JsonMarshallingException(e);
28 }
29 }
30
31 @Deprecated
32 public String marshal(final Object jaxbBean, final Class... jaxbClasses) throws JAXBException
33 {
34 return marshal(jaxbBean);
35 }
36 }