Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

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

public class Main {
    public static <T> String toString(T xml) {
        JAXBContext jc;
        try {
            jc = JAXBContext.newInstance(xml.getClass());
            Marshaller m = jc.createMarshaller();
            m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
            StringWriter writer = new StringWriter();
            m.marshal(xml, writer);
            return writer.toString();
        } catch (JAXBException e) {
            return "";
        }
    }
}