jaxb when xsi:nil=true if any child element exists it is still showing

前提是你 提交于 2019-12-20 06:11:04

问题


I have the below xml output, how can we hide the child element (endDate) when parent element has attribute xsi:nil=true even child element is nillable=true?

//XML Output

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<snapshots xmlns:xsi="w3.org/2001/XMLSchema-instance"; xmlns:ns3="ws.mycompany.com"; mask="PAC">
    <Offers>
        <Offer xsi:type="wsMarketingOfferOP" entityId="1234" xsi:nil="true">
            <endDate xsi:nil="true"/>
        </Offer>
    </Offers>
</snapshots>

// Snapshots class

    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "", propOrder = { "OffersElement"})
    @XmlRootElement(name = "snapshots")
    public class Snapshots<T extends Offer>
    {

        @XmlElement(name = "Offers")
        private OffersElement<T> OffersElement;


        public OffersElement<T> getOffersElement() {
            return offersElement;
        }

        public void setOffersElement(OffersElement<T> offersElement) {
            this.offersElement = offersElement;
        }
    }

// OffersElement class

       @XmlAccessorType(XmlAccessType.NONE)
       @XmlRootElement(name = "Offer")

       public class OffersElement<T> {

        @XmlElementRef(name="Offer")
        List<JAXBElement<T>> listOffers;

        public List<JAXBElement<T>> getListOffers() {
            return listOffers;
        }

        public void setListMarketOffers(List<JAXBElement<T>> listOffers) {
            this.listOffers = listOffers;
        }
     }

//WSOffer class where offers are marshelling, and endate nillable is set to true so that it will appear where it is null.

            @XmlRootElement(name = "Offer")
    @XmlType(name = "", propOrder = { "endDate" })
    @XmlAccessorType(XmlAccessType.FIELD)
    public class WSOffer
    {
        @XmlElement(nillable = true)
        protected WSOffer.EndDate endDate;

        public WSOffer.EndDate getEndDate() {
            return endDate;
        }

        public void setEndDate(WSOffer.EndDate value) {
            this.endDate = value;
        }

        @XmlAccessorType(XmlAccessType.FIELD)
        @XmlType(name = "", propOrder = { "value" })
        public static class EndDate
        {
            @XmlValue
            protected Date value;

            public Date getValue() {
                return value;
            }

            public void setValue(Date value) {
                this.value = value;
            }
        }
       }

来源:https://stackoverflow.com/questions/24303474/jaxb-when-xsinil-true-if-any-child-element-exists-it-is-still-showing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!