Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.ByteArrayOutputStream;

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

public class Main {

    public static String beanToXml(ByteArrayOutputStream out, Object to) {
        try {
            JAXBContext context = JAXBContext.newInstance(to.getClass());
            Marshaller marshaller = context.createMarshaller();
            marshaller.marshal(to, out);
            return new String(out.toByteArray(), "UTF-8");
        } catch (JAXBException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return null;
    }
}