7 Replies Latest reply on Mar 12, 2015 6:02 AM by jeetu

    Loading annotations from dynamic modules

    mayera21

      I have model POJOs that are annotated with org.codehaus.jackson.annotate.JsonIgnoreProperties(ignoreUnknown=true).

      The jar that contains the model objects are deployed to JBoss.

       

      I have another deployment that uses RESTEasy (within SwitchYard) to convert json into those model objects.  Unfortunately, if the incoming JSON contains any extra informtation, it throws an error about an unknown property.  So it's obviously not parsing the JsonIgnoreProperies annotation

       

      I ran jandex on the model objects, generated the jandex.xml, and added  <module name="deployment.mymodel.jar" annotations="true"/> to the jboss-deployment-structure.xml.

      But when I deploy that jar, I get the following exception

      Caused by: org.jboss.modules.ModuleNotFoundException: deployment.mymodel.jar:main

        at org.jboss.modules.ModuleLoader.loadModule(ModuleLoader.java:224) [jboss-modules.jar:1.2.2.Final-redhat-1]

        at org.jboss.as.server.deployment.annotation.CompositeIndexProcessor.deploy(CompositeIndexProcessor.java:70) [jboss-as-server-7.2.1.Final-redhat-10.jar:7.2.1.Final-redhat-10]

        ... 6 more

       

      Just as a test, I set annotations="true" on a random jboss static module and it didn't complain about that--so it doesn't seem it's an issue with simply including annotations="true".  I removed the jandex information and tried again but I still got the same error.

      So I didn't fully test yet to see if I moved mymodel.jar into the static modules directory and if that would fix my issue (but I don't want to deploy the jar statically).

      Can we simply not load annotations from dynamic modules?  Is there some other workaround?

        • 1. Re: Loading annotations from dynamic modules
          ctomc

          What module has jandex index now? a deployment?

           

          jandex is needed only for static modules not for dynamic ones...

           

          what is another deployment name? is it called "mymodel.jar" ?

          do you have dependency to other deployment expressed in jboss-all.xml?

          • 2. Re: Loading annotations from dynamic modules
            mayera21

            Ah--didn't know that jandex was only for static modules.  I had jandex on my dynamic module mymodel.jar.  So I can remove that and apparently the annotations="true" is unnecessary.

            But I'm not sure why the JsonIgnoreProperies isn't taking effect then.  Are there logs that could be enabled that would provide any insight?

             

            As for my setup, the RESTEasy/Switchyard application (let's call it myimpl.jar) has jboss-deployment-structure.xml that references org.hibernate and deployment.mymodel.jar

            But if I make a POST/PUT with additional properties in the json object I get an org.codehaus.jackson.map.exc.UnrecognizedPropertyException

            • 3. Re: Re: Loading annotations from dynamic modules
              mayera21

              Did a little more digging and it definitely is losing my annotation somehow.

              If I run a small test program locally to output the  annotations:

              Annotation[] annotations = MyClass.class.getDeclaredAnnotations(); for(Annotation an: annotations){           System.out.println(an.toString()); }

              I get the following output--which is correct:

              @javax.persistence.Embeddable()

              @org.codehaus.jackson.annotate.JsonIgnoreProperties(ignoreUnknown=true, value=[])

               

              Running that same code within a running JBoss AS7 deployment, I only see the Embeddable annotation.

              • 4. Re: Re: Loading annotations from dynamic modules
                ctomc

                it might be that your deployment that is importing annotations does not have that annotations classes visible?

                 

                try adding dependency also to jackson lib.

                 

                problem is that when annotation is resolved it needs classes from which this annotations come from.

                 

                you could also enable trace loging for "org.jboss.modules" this way you will probably see this in log.

                • 5. Re: Re: Loading annotations from dynamic modules
                  mayera21

                  I added a very similar model class to myimpl.jar and ran similar code to print the class annotations and it showed JsonIgnoreProperties in it's output.  So jboss was loading the jackson libraries correctly.  But not for mymodel.jar.

                   

                  I included  <module name="org.codehaus.jackson.jackson-core-asl" export="true"> in the jboss-deployment-structure.xml of mymodel.jar and it started working

                  • 6. Re: Re: Loading annotations from dynamic modules
                    ctomc

                    Just a side note, you don't need export="true" part in your dep definition

                    • 7. Re: Loading annotations from dynamic modules
                      jeetu

                      Hi Adam,

                       

                      Thanks for asking this question. We exactly had this issue and were pulling our hair out, trying to find the answer, until i luckily found this discussion.

                      I would request you to have better tagging for this discussion so that this can be found easily when searched.

                       

                      Tomaz,

                       

                      Thanks for your answer. It works. But i think the documentation should have this written somewhere. I browsed through the whole documentation and could not find anything about this anywhere. Though the solution makes sense, it's highly unlikely for everybody to think of this.