How to marshal empty string to a single tag

别来无恙 提交于 2019-12-20 06:37:09

问题


I've my object, configured with the code:

object.setName("");

marshaled into following XML:

<object>
    <name></name>
</object>

But I want single tag:

<object>
    <name/>
</object>

Is it easy to do with JAXB for all my objects at once?

UPDATE

Similar question: How to instantiate an empty element with JAXB

It's suggested to use prettifier javax.xml.transform.TransformerFactory.newTransformer(), but without explanation how to use it. Ideally my goal is to get exact code to configure JAXB to get the desired result.

Thanks.


回答1:


The answer to my question was found in another question How to instantiate an empty element with JAXB where it's suggested to either use a prettifier or don't do anything at all because both versions of XML are equivalent.



来源:https://stackoverflow.com/questions/7348743/how-to-marshal-empty-string-to-a-single-tag

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