### Question:
XmlMapper { public static String toXml(Object root) { Class clazz = ClassUtil.unwrapCglib(root); return toXml(root, clazz, null); }  static String toXml(Object root); static String toXml(Object root, String encoding); static String toXml(Object root, Class clazz, String encoding); static String toXml(Collection<?> root, String rootName, Class clazz); static String toXml(Collection<?> root, String rootName, Class clazz, String encoding); static T fromXml(String xml, Class<T> clazz); static Marshaller createMarshaller(Class clazz, String encoding); static Unmarshaller createUnmarshaller(Class clazz);  }### Answer:
@Test public void objectToXml() { User user = new User(); user.setId(1L); user.setName("calvin"); user.getInterests().add("movie"); user.getInterests().add("sports"); String xml = XmlMapper.toXml(user, "UTF-8"); System.out.println("Jaxb Object to Xml result:\n" + xml); assertXmlByDom4j(xml); }
@Test public void toXmlWithListAsRoot() { User user1 = new User(); user1.setId(1L); user1.setName("calvin"); User user2 = new User(); user2.setId(2L); user2.setName("kate"); List<User> userList = Lists.newArrayList(user1, user2); String xml = XmlMapper.toXml(userList, "userList", User.class, "UTF-8"); System.out.println("Jaxb Object List to Xml result:\n" + xml); }