Uploaded image for project: 'CXF'
  1. CXF
  2. CXF-2779

CXF ignores @XmlAttribute when serializing exception

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Invalid
    • 2.2.7
    • Invalid
    • JAXB Databinding
    • None

    Description

      JAXBEncoderDecoder#unmarshallException} doesn't normally write to private fields, so exception data isn't propagated, unless:

      • either the {@link @XmlAccessorType}

        annotation is present on the class and used to set the default access method to something other than the default XmlAccessType#PUBLIC_MEMBER,

      • or the {@link XmlAttribute}

        annotation is present on the individual private members that you want to be serialized.

      The Caucho documentation says:

      Adding @XmlAttribute to a private field will mark that field as serializable.

      and they give the following example which clearly implies that no accessors are required:

      @XmlRootElement
      class Bean {
        @XmlAttribute("sample-field")
        private String _myField;
      }
      

      Nevertheless:

      • JAXBEncoderDecoder#marshallException calls org.apache.cxf.jaxb.JAXBContextInitializer#isFieldAccepted to see whether the field should be copied
      • that method fails to check for the XmlAttribute annotation on the field
      • so its value is never serialized or deserialized

      and the attached test case fails unless:

      • either a public getter and setter are provided to turn the field into a property,
      • or the access type is changed to something other than PUBLIC_MEMBER.

      Attachments

        1. CxfExceptionFieldPropagationTest.java
          4 kB
          Graham Charters
        2. CxfExceptionFieldPropagationTest.java
          6 kB
          Graham Charters

        Activity

          People

            dkulp Daniel Kulp
            gcc Graham Charters
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: