JAXB xml与bean对象的转换

JDK1.7

1.生成xml的字符串
JAXBContext context = JAXBContext.newInstance(示例对象.class);
Marshaller marshaller = context.createMarshaller();
marshaller.marshal(示例对象, 输出流);

2.解析xml文件

JAXBContext context = JAXBContext.newInstance(示例对象.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
示例对象 对象= (示例对象)unmarshaller.unmarshal(new StringReader("待解析字符串"));