package de.jeha.s3srv.xml;

import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import java.io.IOException;
import java.io.StringWriter;

/**
 * @author jenshadlich@googlemail.com
 */
public class JaxbMarshaller {

    private static Marshaller MARSHALLER = null;

    static {
        try {
            MARSHALLER = JaxbContextHolder.getContext().createMarshaller();
            MARSHALLER.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
            MARSHALLER.setProperty(Marshaller.JAXB_FRAGMENT, true);
        } catch (JAXBException e) {
            throw new RuntimeException("Unable to initialize JAXB Marshaller", e);
        }
    }

    public static String marshall(Object object) throws JAXBException, IOException {
        StringWriter stringWriter = new StringWriter();
        stringWriter.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
        stringWriter.append("\n");

        MARSHALLER.marshal(object, stringWriter);
        stringWriter.close();

        return stringWriter.toString();
    }
}

@@ -107,23 +107,136 @@
 java
-.io.IOException
+x.xml.bind.Unmarshaller;%0Aimport javax.xml.transform.stream.StreamSource;%0Aimport java.io.IOException;%0Aimport java.io.StringReader
 ;%0Aim
@@ -388,16 +388,69 @@
  = null;
+%0A    private static Unmarshaller UNMARSHALLER = null;
 %0A%0A    st
@@ -819,16 +819,241 @@
       %7D%0A
+        try %7B%0A            UNMARSHALLER = JaxbContextHolder.getContext().createUnmarshaller();%0A        %7D catch (JAXBException e) %7B%0A            throw new RuntimeException(%22Unable to initialize JAXB Unmarshaller%22, e);%0A        %7D%0A
     %7D%0A%0A 
@@ -1424,16 +1424,221 @@
 ring();%0A
-
     %7D%0A
+%0A    public static %3CT%3E T unmarshall(String xml, Class%3CT%3E clazz) throws JAXBException, IOException %7B%0A        return UNMARSHALLER.unmarshal(new StreamSource(new StringReader(xml)), clazz).getValue();%0A    %7D%0A%0A
 %7D%0A

add unmarshaller