1 public void pushEmployee(EmpPushToTianFangRequest request){ 2 try { 3 StringWriter sw = new StringWriter(); 4 JAXBContext context = JAXBContext.newInstance(EmpPushToTianFangRequest.class); 5 Marshaller marshaller = context.createMarshaller(); 6 marshaller.marshal(request, sw); 7 System.out.println(sw.toString()); 8 } catch (JAXBException e) { 9 e.printStackTrace(); 10 } 11 }
1
marshal方法在JDK中的声明:
void javax.xml.bind.Marshaller.marshal(Object jaxbElement, Writer writer) throws JAXBException
使用
StringWriter 接受
Writer