JAXB is XML-to-Java binding technology enabling transformations
between schema and Java objects and between XML instance documents
and Java object instances. Internally JAXB does all this conversions
between xml and java . This is a parser of xml and then it knows what
component in xml corresponds to what in java and it breaks .
Conversion of this answer from JAXB is done by tools like xjc ( or
codgen plugin) . Mapping may be likexsd:string java.lang.String
xsd:integer java.math.BigInteger
JaxRs is different . This is set of specifications for handling
requests . Meaning that it says “GET(“/foo”) ” means handle a get
call with url /foo . It only states that . How it is done ? Yes,that
is called implementation of this spec . There are number of
implementations like restlet,resteasy,jersey,apache cxf etc .
This is analogus to logic and way you implement in maths . the
algorithm idea is bucket search .This can be implemented in any way .
In java terms JaxRs is interface and these 4 restlet,
jersey,apache cxf are implementations of the interface .
现在请说明我的理解是否正确.然后告诉他们如何相关.请帮忙 .如果可能的话,图片说明会更有帮助.
JAXB – 定义用于将Java域对象转换为/从XML转换的标准化元数据和运行时API.
JAX-RS – 定义用于创建RESTful服务的标准化元数据和运行时API.默认情况下,应用程序/ xml媒体类型JAX-RS将使用JAXB将对象转换为/从XML转换.
例
在以下示例中,当执行GET操作时,JAX-RS实现将返回一个Customer.将使用JAXB impl将该客户端实例转换为客户端实际接收的XML.
package org.example.service; import javax.ejb.*; import javax.ws.rs.*; import javax.ws.rs.core.MediaType; import org.example.model.*; @Stateless @LocalBean @Path("/customers") public class CustomerResource { @GET @Produces(MediaType.APPLICATION_XML) @Path("{id}") public Customer read(@PathParam("id") int id) { Customer customer = new Customer(); customer.setId(id); customer.setFirstName("Jane"); customer.setLastName(null); PhoneNumber pn = new PhoneNumber(); pn.setType("work"); pn.setValue("5551111"); customer.getPhoneNumbers().add(pn); return customer; } }