本文主要是介绍O/X mapping概念及JAXB简介,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Object/XML Mapping (O/X mapping)指XML文档与Java对象之间的映射关系。
XML Marshalling(也称为XML Serialization)是指在XML文档与Java对象之间的转换过程。
将Java对象转换为XML文档,称为marshaller 。
将XML文档转换为Java对象,称为unmarshaller 。
常见的O/Xmapping API:
- JAXB
- XMLBeans
- JiBX
- Castor
- XStream
JAXB specification provides a way to map Java classes to XMLrepresentations,是JCP的标准之一:
- JAXB 1.0,JSR-31
- JAXB 2.0/2.1/2.2,JSR-222
JAXB RI是JAXB规范的实现。JAXB project的主要目的就是开发并维护JAXB RI,当前最新版是2014.10发布的JAXB RI 2.2.11。
此外,JAXB project还提供了如下扩展工具:
- Jsonix - JAXB analog for JavaScript
- Hyperjaxb3 - relational persistence for JAXB objects with JPA (Hibernate,TopLink etc.)
- XJCplugins - variousenhancements to XJC developed by the community
- MavenJAXB2 Plugin - actualMaven plugin for JAXB2
- JAXB2reflection library
- JAXBIntroductions - put JAXBannotations on 3rd party classes
- Annox - allows defining JAXB annotations in XML resources
- JAXB Workshop, Eclipse Plugins
从JDK6开始,JavaArchitecture for XML Binding (JAXB) 成为JDK的组成部分:
- JAXB RI 2.0.3 in JDK 6 first release - JDK6 u3
- JAXB 2.0 in JavaEE 5
- JAXB RI 2.1.3 in JDK 6 u4
- JAXB RI 2.1.10 in JDK 6 u14
- JAXB RI 2.2.4-1 in JDK 7 first release
- JAXB 2.2.4 in JavaEE 6
- JAXB RI 2.2.4-2 in JDK 7 u6
- JAXB 2.2.11 in JDK 8
- JAXB 2.2.11 in JavaEE 7
two features of JAXB:
- to marshal Java objects into XML
- to unmarshal XML back into Java objects
1. XML Schema -> Java class
JAXB provides“xjc” tool to convert XML Schema to class representations.
JAXB bindingcompiler xjc is also part of the JDK6,it is a command line tool which can beused togenerate binding classes basedon an existing XSD schema description.
2. Javaclass -> XML Schema
JAXB includes a“schemagen” tool which can create an XML Schema from a set of annotatedclasses.
参考文献:
JAXB project官网https://jaxb.java.net/
这篇关于O/X mapping概念及JAXB简介的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!