Flexible marshalling with JAXB

后端 未结 2 1998
一生所求
一生所求 2021-01-23 05:39

I\'m hoping to have a flexible way of marshalling objects. A verbose version for single objects and a less-verbose version for multiple object versions.

For example, co

2条回答
  •  不思量自难忘°
    2021-01-23 05:56

    Here comes another idea. Could be a bad idea but somewhat easy.

    class Department {
    
        @XmlElement(required = true)
        public Link getSelf() {
            return self;
        }
    
        @XmlElement(required = false) // default
        public Link getParent() {
            if (verbose) {
                return parent;
            }
            return null;
        }
    
        @XmlElement(required = false) // default
        public String getSpecialty() {
            if (verbose) {
                return specialty;
            }
            return null;
        }
    
        @XmlTransient
        private boolean verbose;
    }
    

提交回复
热议问题