我在RESTAPI工作。我们有XML模式和抽象类型。我们添加了@Mapped注释来支持json。
但是我们在执行POST操作时仍然会遇到JAXB绑定异常。但GET操作适用于JSON。在这种情况下需要做什么?
我们正在使用jettison库。
对于JAX-RS实现,我们使用RESTEasy库.JAXB生成的类驻留在“net.com.schema.services”包中。
@GET
@Produces({"application/xml","application/json"})
@Mapped(namespaceMap = {
@XmlNsMap(namespace = "services.schema.com.net", jsonName = ""),
@XmlNsMap(namespace = "http://www.w3.org/2001/XMLSchema-instance", jsonName = "")
})
@Path(ID_REGEX)
@RBAC(type = { CRUDEnum.READ }, capability = { "APICap" })
public JAXBElement<RESTOperationType> getCustomer(@PathParam("id") int customerId);
@POST
@Path(CUSTOMERS)
@Produces({"application/xml","application/json"})
@Mapped(namespaceMap = {
@XmlNsMap(namespace = "services.schema.com.net ", jsonName = ""),
@XmlNsMap(namespace = "http://www.w3.org/2001/XMLSchema-instance", jsonName = "")
})
@Consumes({"application/xml","application/json"})
@RBAC(type = { CRUDEnum.CREATE }, capability = { "APICap" })
public JAXBElement<RESTOperationType> addCustomer(JAXBElement<RESTOperationType> restOprn)
我尝试了上面的代码,我得到了POST Operation的绑定异常。我尝试了另一种方法。
@POST
@Path(CUSTOMERS)
@Produces({"application/xml","application/json"})
@Mapped(namespaceMap = {
@XmlNsMap(namespace = "services.schema.com.net ", jsonName = ""),
@XmlNsMap(namespace = "http://www.w3.org/2001/XMLSchema-instance", jsonName = "")
})
@Consumes({"application/xml","application/json"})
@RBAC(type = { CRUDEnum.CREATE }, capability = { "APICap" })
public JAXBElement<RESTOperationType> addCustomer(@Mapped(namespaceMap = {
@XmlNsMap(namespace = "services.schema.com.net ", jsonName = ""),
@XmlNsMap(namespace = "http://www.w3.org/2001/XMLSchema-instance", jsonName = "")
})JAXBElement<RESTOperationType> restOprn);
我在addCustomer方法中提供了@Mapped注释。现在,Binding异常被解析,并在尝试从JSON输入读取数据时获得NullPointer异常。