Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;

import java.io.IOException;

import java.io.StringWriter;

public class Main {
    public static String asXml(Object object) throws IOException {
        try {
            StringWriter writer = new StringWriter();
            JAXBContext context = JAXBContext.newInstance(object.getClass());
            Marshaller m = context.createMarshaller();
            m.marshal(object, writer);

            return writer.toString();

        } catch (Exception e) {
            return "";
        }
    }
}