jaxb
  1. jaxb
  2. JAXB-871

Disabled fields and multiple-inherence (override once => override for sub-classes)

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.2.4, 2.2.4u1
    • Fix Version/s: 2.2.6
    • Component/s: None
    • Labels:
      None

      Description

      I've been running with an issue caused by the checkOverrideProperties() method which has been added in JAXB 2.2, so I've only been running with this issue since I upgraded the JAXB library in my application..

      I'll just give an example, and I think this should be understandable.

      Here is my model:

       
      public abstract class Parent {
          private String element1;
          private String element2;
      
          public String getElement1() {
              return element1;
          }
      
          public void setElement1(String element1) {
              this.element1 = element1;
          }
      
          public String getElement2() {
              return element2;
          }
      
          public void setElement2(String element2) {
              this.element2 = element2;
          }
      }
      
      @XmlRootElement(name = "child1")
      @XmlAccessorType(XmlAccessType.FIELD)
      public class Child1 extends Parent {
          private String element1;
          private String element3;
      
          public String getElement1() {
              return element1;
          }
      
          public void setElement1(String element1) {
              this.element1 = element1;
          }
      
          public String getElement3() {
              return element3;
          }
      
          public void setElement3(String element3) {
              this.element3 = element3;
          }
      }
      
      @XmlRootElement(name = "child2")
      @XmlAccessorType(XmlAccessType.FIELD)
      public class Child2 extends Parent
      {
          private String element4;
      
          public String getElement4() {
              return element4;
          }
      
          public void setElement4(String element4) {
              this.element4 = element4;
          }
      }
      
      @XmlRootElement(name = "wrapper")
      @XmlAccessorType(XmlAccessType.FIELD)
      public class Wrapper
      {
          private Child1 child1;
          private Child2 child2;
      
          public Child1 getChild1() {
              return child1;
          }
      
          public void setChild1(Child1 child1) {
              this.child1 = child1;
          }
      
          public Child2 getChild2() {
              return child2;
          }
      
          public void setChild2(Child2 child2) {
              this.child2 = child2;
          }
      }
      

      Here is the instance of my model:

       
      final Child1 child1 = new Child1();
      child1.setElement1("element1-1");
      child1.setElement2("element1-2");
      child1.setElement3("element1-3");
      
      final Child2 child2 = new Child2();
      child2.setElement1("element2-1");
      child2.setElement2("element2-2");
      child2.setElement4("element2-4");
      
      final Wrapper wrapper = new Wrapper();
      wrapper.setChild1(child1);
      wrapper.setChild2(child2);
      

      Using JAXB 2.2.4 or 2.2.4-1 to marhsall the objects, I get the following XML :

       
      <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
      <wrapper>
      	<child1>
      		<element2>element1-2</element2>
      		<element1>element1-1</element1>
      		<element3>element1-3</element3>
      	</child1>
      	<child2>
      		<element2>element2-2</element2>
      		<element4>element2-4</element4>
      	</child2>
      </wrapper>
      

      As you can see the child2 element minus the element1 subitem. This is because the child1 inherence disabled element1 in parent. Disabling it for child1 is okay, but I don't think it should be disabled for child2 as well.

      The easiest workaround is to avoid any override in the java model.

      Thank you for your interest.

      1. BaseObj.java
        0.5 kB
        gezr
      2. DerivedObj1.java
        0.4 kB
        gezr
      3. DerivedObj2.java
        0.3 kB
        gezr
      4. op1_Response_with_override.xml
        0.4 kB
        gezr
      5. op1_Response.xml
        0.4 kB
        gezr
      6. op2_Response_with_override.xml
        0.4 kB
        gezr
      7. op2_Response.xml
        0.4 kB
        gezr
      8. package-info.java
        0.3 kB
        gezr
      9. SampleService_with_override.wsdl
        4 kB
        gezr
      10. SampleService.java
        0.1 kB
        gezr
      11. SampleService.wsdl
        4 kB
        gezr
      12. SampleServiceImpl.java
        0.5 kB
        gezr

        Activity

        Hide
        Martin Grebac added a comment -

        This has been introduced with 804 fix, agree it does not work properly. Since there are voices seeing this as a regression even if the child2 property would not be hidden as expected, I think the best solution is to revert this back to the original behaviour, improve the fix and bind it to a switch. I don't want to remove the fix completely because this is closer to what moxy does as well.

        Show
        Martin Grebac added a comment - This has been introduced with 804 fix, agree it does not work properly. Since there are voices seeing this as a regression even if the child2 property would not be hidden as expected, I think the best solution is to revert this back to the original behaviour, improve the fix and bind it to a switch. I don't want to remove the fix completely because this is closer to what moxy does as well.
        Hide
        Martin Grebac added a comment -

        Fixed in 22 branch.

        Show
        Martin Grebac added a comment - Fixed in 22 branch.
        Hide
        gezr added a comment - - edited

        Added sample web service to reproduce the problem:

        Steps to reproduce:

        • Uncomment getDate()/setDate(Date) methods in the DerivedObj1.java class
        • Compile and run service

        The difference will be on the response to the SampleService#op2 method call from which ns2:date field disappears:

        • Before override:
          <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
             <soap:Body>
                <op2Response xmlns="http://services.jaxb.java.net" xmlns:ns2="http://objects.jaxb.java.net">
                   <op2Return>
                      <ns2:date>2012-07-18T18:10:43.235+02:00</ns2:date>
                      <ns2:name>Derived 2</ns2:name>
                      <ns2:time>1342627843239</ns2:time>
                   </op2Return>
                </op2Response>
             </soap:Body>
          </soap:Envelope>
          
        • After override in DerivedObj1:
          <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
             <soap:Body>
                <op2Response xmlns="http://services.jaxb.java.net" xmlns:ns2="http://objects.jaxb.java.net">
                   <op2Return>
                      <ns2:name>Derived 2</ns2:name>
                      <ns2:time>1342628337325</ns2:time>
                   </op2Return>
                </op2Response>
             </soap:Body>
          </soap:Envelope>
          

        Environment:

        • Java:
          java version "1.7.0_05"
          Java(TM) SE Runtime Environment (build 1.7.0_05-b05)
          Java HotSpot(TM) Client VM (build 23.1-b03, mixed mode, sharing)
          
        • JAXB:
          jdk1.7.0_05\bin>wsgen -version
          JAX-WS RI 2.2.4-b01
          
          jdk1.7.0_05\bin>xjc -version
          xjc 2.2.4
          
        Show
        gezr added a comment - - edited Added sample web service to reproduce the problem: SampleService.java - service definition SampleServiceImpl.java - service implementation BaseObj.java - definition of the base object from which results are constructed DerivedObj1.java - definition of first result object (the one that will add override) DerivedObj2.java - definition of second result object SampleService.wsdl - WSDL file for web service without overridden properties op1_Response.xml - SOAP response to SampleService#op1 call op2_Response.xml - SOAP response to SampleService#op2 call SampleService_with_override.wsdl - WSDL file for web service when methods getDate() and setDate(Date) are uncommented in DerivedObj1.java op1_Response_with_override.xml - SOAP response to SampleService#op1 call when DerivedObj1 overrides getDate() / setDate(Date) op2_Response_with_override.xml - SOAP response to SampleService#op2 call when DerivedObj1 overrides getDate() / setDate(Date) Steps to reproduce: Uncomment getDate() / setDate(Date) methods in the DerivedObj1.java class Compile and run service The difference will be on the response to the SampleService#op2 method call from which ns2:date field disappears: Before override: <soap:Envelope xmlns:soap = "http://schemas.xmlsoap.org/soap/envelope/" > <soap:Body> <op2Response xmlns= "http://services.jaxb.java.net" xmlns:ns2 = "http://objects.jaxb.java.net" > <op2Return> <ns2:date> 2012-07-18T18:10:43.235+02:00 </ns2:date> <ns2:name> Derived 2 </ns2:name> <ns2:time> 1342627843239 </ns2:time> </op2Return> </op2Response> </soap:Body> </soap:Envelope> After override in DerivedObj1 : <soap:Envelope xmlns:soap = "http://schemas.xmlsoap.org/soap/envelope/" > <soap:Body> <op2Response xmlns= "http://services.jaxb.java.net" xmlns:ns2 = "http://objects.jaxb.java.net" > <op2Return> <ns2:name> Derived 2 </ns2:name> <ns2:time> 1342628337325 </ns2:time> </op2Return> </op2Response> </soap:Body> </soap:Envelope> Environment: Java : java version "1.7.0_05" Java(TM) SE Runtime Environment (build 1.7.0_05-b05) Java HotSpot(TM) Client VM (build 23.1-b03, mixed mode, sharing) JAXB : jdk1.7.0_05\bin>wsgen -version JAX-WS RI 2.2.4-b01 jdk1.7.0_05\bin>xjc -version xjc 2.2.4
        Hide
        gezr added a comment - - edited

        I understand that the issue was already fixed in 2.2.6 which as far as I know was not released yet. However what bothers me more is that in JDK 7 (up to update 5) the JAXB distribution is still broken. So I have couple of concerns:

        • Will the fix be back-ported to 2.2.4 version?
        • When the fix will be released?
        • Will the fix be included in JDK 7?
        • When such a fix could be included in JDK 7 distribution?

        The reason for the JDK 7 question is because we have recently converted project from Java 6 to Java 7 and now we hit this bug. For us it is a blocker for a delivery of our product.

        Show
        gezr added a comment - - edited I understand that the issue was already fixed in 2.2.6 which as far as I know was not released yet. However what bothers me more is that in JDK 7 (up to update 5) the JAXB distribution is still broken. So I have couple of concerns: Will the fix be back-ported to 2.2.4 version? When the fix will be released? Will the fix be included in JDK 7? When such a fix could be included in JDK 7 distribution? The reason for the JDK 7 question is because we have recently converted project from Java 6 to Java 7 and now we hit this bug. For us it is a blocker for a delivery of our product.

          People

          • Assignee:
            Martin Grebac
            Reporter:
            guinotphil
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: