有人可以向我解釋writer.toString如何保存客戶數據嗎?看起來,元帥(客戶,作家)以某種方式修改了作者。下面請看,感謝:StringWriter如何採取新的價值?
Customer customer = new Customer();
customer.setId(42);
customer.setName("Bill Burke");
JAXBContext ctx = JAXBContext.newInstance(Customer.class);
StringWriter writer = new StringWriter();
ctx.createMarshaller().marshal(customer, writer);
[在這裏看到:]
String custString = writer.toString(); // how did writer suddenly take on value?
customer = (Customer)ctx.createUnmarshaller()
.unmarshal(new StringReader(custString));