javax.xml.bind.UnmarshalException 伊巴托

javax.xml.bind.UnmarshalException ibator

我不知道我做错了什么

@Path("/orderService")
public class PlaceOrder {

    @POST
    @Path("/placeOrder")
    @Consumes({ MediaType.APPLICATION_JSON })
    public void placeOrder(PlaceOrderRequest placeOrderRequest,@Context HttpHeaders headers, @Context HttpServletRequest request,@Context HttpServletResponse response)
            throws GwExceptions {
        if(5>2){
            boolean truechils=true;
        }
    }
}

这是我的地方OderReques class

@XmlRootElement(name = "placeorderequest")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(propOrder = {"userName","numberOfItem","orderTimeslot",
        "userAddress","addressLandmark","orderStatus","totalPrice"})
public class PlaceOrderRequest extends RestApiResponseParent{

    @XmlElement(name = "userName", required = true)
    @SerializedName("userName")
    private String userName;

    @XmlElement(name = "numberOfItem", required = true)
    @SerializedName("numberOfItem")
    private int numberOfItem;

    @XmlElement(name = "orderTimeslot", required = true)
    @SerializedName("orderTimeslot")
    private Date orderTimeslot;

    @XmlElement(name = "userAddress", required = true)
    @SerializedName("userAddress")
    private String userAddress;

    @XmlElement(name = "addressLandmark", required = true)
    @SerializedName("addressLandmark")
    private String addressLandmark;

    @XmlElement(name = "orderStatus", required = true)
    @SerializedName("orderStatus")
    private String orderStatus;

    @XmlElement(name = "totalPrice", required = true)
    @SerializedName("totalPrice")
    private Double totalPrice;


    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public int getNumberOfItem() {
        return numberOfItem;
    }

    public void setNumberOfItem(int numberOfItem) {
        this.numberOfItem = numberOfItem;
    }

    public Date getOrderTimeslot() {
        return orderTimeslot;
    }

    public void setOrderTimeslot(Date orderTimeslot) {
        this.orderTimeslot = orderTimeslot;
    }

    public String getUserAddress() {
        return userAddress;
    }

    public void setUserAddress(String userAddress) {
        this.userAddress = userAddress;
    }

    public String getAddressLandmark() {
        return addressLandmark;
    }

    public void setAddressLandmark(String addressLandmark) {
        this.addressLandmark = addressLandmark;
    }

    public String getOrderStatus() {
        return orderStatus;
    }

    public void setOrderStatus(String orderStatus) {
        this.orderStatus = orderStatus;
    }

    public Double getTotalPrice() {
        return totalPrice;
    }

    public void setTotalPrice(Double totalPrice) {
        this.totalPrice = totalPrice;
    }       
}

*我正在使用 rest api 客户端发送请求 * 这里是错误日志


Caused by: com.sun.istack.SAXParseException2; columnNumber: 0; 
    unexpected element (uri:"", local:"userName"). 
    Expected elements are <{}common_object>,
                          <{}placeorderequest>,
                          <{}response_parent>
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:662)
at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:258)
at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:253)
at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportUnexpectedChildElement(Loader.java:120)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext$DefaultRootLoader.childElement(UnmarshallingContext.java:1063)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:498)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:480)
at com.sun.xml.bind.v2.runtime.unmarshaller.InterningXmlVisitor.startElement(InterningXmlVisitor.java:75)
at com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.handleStartElement(StAXStreamConnector.java:246)
at com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.bridge(StAXStreamConnector.java:180)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:415)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:386)
at org.apache.cxf.jaxrs.provider.json.JSONProvider.readFrom(JSONProvider.java:232)
... 43 more
Caused by: javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"userName"). 
      Expected elements are <{}common_object>,
                            <{}placeorderequest>,
                            <{}response_parent>

我收到的回复是

JAXBException occurred : unexpected element (uri:"", local:"userName").
    Expected elements are <{}common_object>,
                          <{}placeorderequest> 
                          <{}response_parent>. 
    unexpected element (uri:"", local:"userName"). 
    Expected elements are <{}common_object>,
                          <{}placeorderequest>,
                          <{}response_parent>. 

如有任何帮助,我们将不胜感激

cxf-dev 开发板上的一个答案建议您需要为 @XmlRootElement

设置名称空间

所以:@XmlRootElement(name = "placeorderequest", namespace="")