castor

mapping/class/field/@required="false" does not eliminate null element

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Won't Fix
  • Affects Version/s: 1.0.5
  • Fix Version/s: 1.1 M3
  • Component/s: XML
  • Labels:
    None
  • Environment:
    OS: Windows XP Pro SP2
    JDK: 1.4.2
  • Testcase included:
    yes
  • Number of attachments :
    1

Description

When marshalling the HearingDetailsVO, I only set value for <applicationNo> field of HearingDetailsVO class. In the mapping file, all the fields are optional by setting /mapping/class/field/@required="false".
However, the retNode after marshalling contains null elements like <NOA/><caseNo/><designation/>, etc.

In the attachment file, the CISClient3.java contains the method testCIS();
the CISClient3Test.java is the JUnit test script;
The HearingDetailsVO.xml is the mapping file;
and the HearingDetailsVO.java is the domain entity.

Activity

Hide
Werner Guttmann added a comment -

Hi, just found the reason why you are seeing empty elements being generated as part of marshalling. In the constructor of your domain entity, you are assigned an empty string ("") to almost all of the members. This will basically prevent Castor from telling that a value has not been assigned to a member yet. Castor internally uses 'null's for such checks.

I have just commented out that code in question., and the XML produced by Castor after doing so meets your expected output.

Show
Werner Guttmann added a comment - Hi, just found the reason why you are seeing empty elements being generated as part of marshalling. In the constructor of your domain entity, you are assigned an empty string ("") to almost all of the members. This will basically prevent Castor from telling that a value has not been assigned to a member yet. Castor internally uses 'null's for such checks. I have just commented out that code in question., and the XML produced by Castor after doing so meets your expected output.
Hide
Werner Guttmann added a comment -

As mentioned above, there's a work-around to prevent a misunderstanding.

Show
Werner Guttmann added a comment - As mentioned above, there's a work-around to prevent a misunderstanding.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: