How do I prevent JAXB from binding superclass methods of the @XmlRootElement when marshalling?

后端 未结 6 1854
谎友^
谎友^ 2020-12-30 09:10

I have a class that is annotated as the @XmlRootElement with @XmlAccessorType(XmlAccessType.NONE). The problem that I am having is that the superc

6条回答
  •  佛祖请我去吃肉
    2020-12-30 09:45

    A solution I have found, but which might not work for you depending on what you want to do, is to override the getters you want to ignore and let them return null. The JAXB specs, and by extension the implementations, ignore fields that contain a null value. Note that if you still need to be able to access the superclass value itself using the subclass, you may need to add a secondary accessor method that is not a getter and adjust your code accordingly.

提交回复
热议问题