This article mainly introduces detailed information about the conversion between xml and Java objects. For more information about the conversion between xml and Java objects, see the next article, for more information, see
Conversion between xml and Java objects
1. xstream resolution packets
XStreamComponent x = XStreamComponent.newInstance(); x.processAnnotations(new Class[]{EquityExchangeDetail.class,PearTicketCustomerDTO.class,Date.class,Integer.class}); EquityExchangeDetail ptd = (EquityExchangeDetail) x.fromXML(xml);
2. xstream encapsulation packets
XStreamComponent xres = XStreamComponent.newInstance(); xres.processAnnotations(new Class[]{TransResult.class}); String result=xres.toXML(transResult);
3. Annotation:
@ XStreamAlias ("customerInfo") // message
The corresponding class name of the node is "PearTicketCustomerDTO" public class PearTicketCustomerDTO {@ XStreamAlias ("idno") // message
The class attribute "idno" private String idno corresponding to the node; @ XStreamOmitFieldprivate Long ticketId; // none in the message
Node. the class attribute ticketId is ignored during parsing.
4. method comparison
X. processAnnotations (new Class [] {PearTicketDTO. class}): Read Class name annotation x. alias (new class [] {PearTicketDTO. Class}): Do not read class name annotation
5. parse packets
X. alias ("Equities", List. class); -- sets the packet node
Convert to List object x. alias ("Equity", Equity. class); -- converts the packet node
Convert to Equity class object List
Equities = (List
) X. fromXML (xml); -- start conversion