jersey
  1. jersey
  2. JERSEY-988

wadl generator enhancement for JAXB objects with non-public default constructors

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.12
    • Fix Version/s: 1.13
    • Component/s: core
    • Labels:
      None

      Description

      We use the wadl to generate client code. The element in the response representation is needed for the client generator to produce the handy method:

       public sandbox.Model getModelAsApplicationXml() {
      ..
      }
      

      Public default constructor of a simple JAXB object (sandbox.Model) produces the correct WADL response element.

      <ns2:response>
        <ns2:representation mediaType="application/xml" element="model" />
        <ns2:representation mediaType="application/json" element="model" />
      </ns2:response>
      

      Less than public default constructor of the same object produces the correct WADL response element.

      <ns2:response>
        <ns2:representation mediaType="application/xml" />
        <ns2:representation mediaType="application/json" />
      </ns2:response>
      

      Changing a few lines of Code in the WadlGeneratorJAXBGrammarGenerator now allows for non-public default constructors.

      ...
      return new Resolver() {
        @Override
         public QName resolve(Class type) {
      	Object parameterClassInstance = null;
      	try {
      		Constructor<?> defaultConstructor = type.newInstance();
      ...
      

      to

      ...
      return new Resolver() {
        @Override
         public QName resolve(Class type) {
      	Object parameterClassInstance = null;
      	try {
      		Constructor<?> defaultConstructor = type.getDeclaredConstructor();
      		defaultConstructor.setAccessible(true);
      		parameterClassInstance = defaultConstructor.newInstance();
      ...
      

      Does the trick.

      Path file attached.

        Activity

        Hide
        Pavel Bucek added a comment -

        fixed in the trunk, thanks!

        Show
        Pavel Bucek added a comment - fixed in the trunk, thanks!
        Hide
        aroller added a comment -

        that's great. I'll be sure to verify once 1.13 comes out. You guys are great!

        Show
        aroller added a comment - that's great. I'll be sure to verify once 1.13 comes out. You guys are great!
        Hide
        Pavel Bucek added a comment -

        Actually, it would be better to verify with current snapshot version to give us an opportunity to adjust some things (if necessary) before 1.13 final.

        Show
        Pavel Bucek added a comment - Actually, it would be better to verify with current snapshot version to give us an opportunity to adjust some things (if necessary) before 1.13 final.

          People

          • Assignee:
            Pavel Bucek
            Reporter:
            aroller
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: