How to wrap sublist with jaxb

后端 未结 3 969
孤独总比滥情好
孤独总比滥情好 2021-02-19 09:31

When trying to map a customer-> order 1:n relationship with jaxb 2.2.6 I\'d like to get the list of orders wrapped in a separate node \"orders\".

currently the result is

3条回答
  •  时光取名叫无心
    2021-02-19 09:44

    Instead of

    /**
     * getter for orders
     * @return orders
     */
    @XmlElement(name="orders", type=OrderJaxbDao.class)
    public List getOrders() { return orders; };
    

    You need

    /**
     * getter for orders
     * @return orders
     */
    @XmlElement(name="order", type=OrderJaxbDao.class)
    @XmlElementWrapper(name="orders")
    public List getOrders() { return orders; };
    

    The @XmlElementWrapper name is the name of the wrapping element (orders) and the @XmlElement name is the name of the per-entry element inside the wrapper (order).

提交回复
热议问题