Axis2
  1. Axis2
  2. AXIS2-5109

optional attribute must not be serialized if not explicitly set

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Critical Critical
    • Resolution: Unresolved
    • Affects Version/s: 1.6.0
    • Fix Version/s: None
    • Component/s: adb
    • Labels:
      None
    • Environment:
      Linux 2.6.35.13-92.fc14.i686.PAE
      Java(TM) SE Runtime Environment (build 1.6.0_23-b05)

      Description

      All the attributes are serialized with default values even if they are not explicitly set.
      This is a problem because the default value of an attribute is a contract between the client and the web service provider and the framework should not override it.

      <xs:complexType name="Sample">
      <xs:sequence />
      <xs:attribute name="BooleanAttribute" type="xs:boolean" />
      <xs:attribute name="IntAttribute" type="xs:int" use="required"/>
      <xs:attribute name="StringAttribute" type="xs:string" use="optional"/>
      </xs:complexType>

      If I don't set any attribute the generated xml look like

      <Sample BooleanAttribute="false" IntAttribute="0"/>

      This is completely wrong because the default values for my optional attributes can be different.
      It should be (please remember that - as per specification - all attributes are optional by default)

      <Sample/>

      The workaround for xs:int attribute is to explicitly set it to java.lang.Integer.MIN_VALUE because in serialization the code is
      if (localAge != java.lang.Integer.MIN_VALUE) {
      writeAttribute("",
      "IntAttribute",
      org.apache.axis2.databinding.utils.ConverterUtil.convertToString(localIntAttribute), xmlWriter);

      But for xs:boolean attribute there is no workaround because in serialization the code is
      if (true)

      { writeAttribute("", "BooleanAttribute", org.apache.axis2.databinding.utils.ConverterUtil.convertToString(localBooleanAttribute), xmlWriter); }

        Activity

          People

          • Assignee:
            Unassigned
            Reporter:
            Marco Benuzzi
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:

              Development