How to instantiate an empty element with JAXB

前端 未结 4 1483
-上瘾入骨i
-上瘾入骨i 2020-12-10 04:30

I use JAXB to create XML messages. The XML I need to create is (for the sake of simplicity):


  
4条回答
  •  余生分开走
    2020-12-10 05:06

    I wanted the same thing, effectively

    rather than
    during the xml serialization process.

    Since a null value - rather than an empty string - will produce the correct result, I modified my setter method to set the value explicitly to null:

    public void setHeader(String header) {
        this.header = "".equals(header) ? null : header;
    }
    

提交回复
热议问题