开发者

How to marshal empty string to a single tag

开发者 https://www.devze.com 2023-04-03 07:58 出处:网络
I\'ve my object, configured with the code: object.setName(\"\"); marshaled into following XML:开发者_如何学Python

I've my object, configured with the code:

object.setName("");

marshaled into following XML:

开发者_如何学Python
<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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号