JAXB - java xml parsing

Common API

JAXBContext class, is the entrance application, and create a sequence deserialized by the class, i.e. the object marshalling and unmarshalling an object;

Marshaller grouping interface will serialize Java objects into XML data;

Unmarshaller solution set of interfaces, XML data deserialized into Java objects.

 

Core comment

@XmlRootElement, the Java class or enum mapped into XML root element, must be the only one annotation, name attribute specifies the name of the root node, defaults to the class name in lowercase is not specified;

@XmlElement, the Java class mapped to XML attributes of a node element, name attribute customizable element name;

@XmlAttribute, the Java class attribute is mapped to a property XML node element, name attribute can be custom property name;

@XmlType, Java class or mapping enumerated types to XML Schema type, often, @ XmlAccessorType shared with @ XmlRootElement, propOrder attribute definition field generated XML node order;

@XmlAccessorType, the control sequence of fields or attributes. There are four attributes XmlAccessType constant value: FIELD JAXB automatically binding indicates a Java class for each non-stationary (static), non-transitory (designated by @XmlTransient) field to the XML; PROPERTY java object represented by all the getter binding / setter way to attribute to XML; PUBLIC_MEMBER represent Java objects in all of the member variables and access to public member variables accessed through getter / setter way, which is the default value; NONE indicates that the Java object mapping is not all properties as XML elements;

@XmlAccessorOrder, sorting control JAXB binding class attributes and fields, there are two attributes, AccessorOrder.ALPHABETICAL-- order of the XML generated in alphabetical order book, XmlAccessOrder.UNDEFINED-- not sorted, the default value for;

@XmlJavaTypeAdapter, custom adapter (i.e., extend the abstract class and covering XmlAdapter Marshal () and the unmarshal () method), to solve the date (a Date), number (Number) format issues;

@XmlElementWrapper, for an array or collection (i.e., member variables comprising a plurality of elements), which generates a set of XML elements or array package (referred to as a wrapper), which can only be used on the set of annotations;

@XmlTransient, used to indicate when a Java object mapping XML, ignore this attribute, this element does not appear in the generated XML file.

 

Reference material

JAXB application examples

Guess you like

Origin www.cnblogs.com/wangwangfei/p/11240623.html