How to represent null value as empty element with JAXB?

前端 未结 4 780
[愿得一人]
[愿得一人] 2020-12-01 06:58

My XSD structure is like the below:-


         


        
4条回答
  •  甜味超标
    2020-12-01 07:32

    I voted up gbvb's answer.

    I don't understand why do you want this but.

    The empty element with xmlns:xsi and xsi:nil is the right way to go.

    Without those attributes any reasonable parsers will give you the empty string even if the element is self-closed.

    Say you want to give clients an integer value which means the highest score in many players' scores.

    When you can calculate you can give the right value. When there is no player who actually scored yet, you should the right value as NULL or nil which means there is no record accumulated.

    98
    

    Can be said the highest score is 98 of of 128 tries.

    And

    
    

    Can be said there is no highest score because there is no scores recorded.

    But

    
    

    Doesn't mean anything but a simple self-closed empty element.

提交回复
热议问题