public static String toXml(Object object) {
        if (object == null) {
            throw new NullPointerException("object对象不存在!");
        }
        JAXBContext jc = null;
        Marshaller m = null;
        String xml = null;
        try {
            jc = JAXBContext.newInstance(object.getClass());
            m = jc.createMarshaller();
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            m.marshal(object, bos);
            xml = new String(bos.toByteArray());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return xml;
    }
public static String toXml ( Object object ) { if ( object == null ) { throw new NullPointerException ( "object对象不存在!" ) ; } JAXBContext jc = null ; Marshaller m = null ; String xml = null ; try { jc = JAXBContext . newInstance ( object . getClass ( ) ) ; m = jc . createMarshaller ( ) ; ByteArrayOutputStream bos = new ByteArrayOutputStream ( ) ; m . marshal ( object , bos ) ; xml = new String ( bos . toByteArray ( ) ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } return xml ; }
对象转xml

@param object
@return