3 Replies Latest reply on May 4, 2012 8:05 AM by Freeman(Yue) Fang

    Can't produce JAXB object messages

    nicolas duminil Master

      Greetings,

       

      I have a producer who instantiates and initializes object and produces these messages in a queue. A consumer consumes these messages but they aren't initialized. I mean that all the primtive properties are 0 and all the other properties are null. I didn't understand what happened but, given that the classes of these messages were extending JAXB objects, I modified them such that to avoid that. Doing that solved the problem.

       

      So my question: is there any problem with JAXB objects, what could be the explanation of the described scenario ?

       

      Many thanks in advance,

       

      Nicolas

        • 1. Re: Can't produce JAXB object messages
          Claus Ibsen Master

          Are you sending JAXB objects over JMS as javax.jms.ObjectMessage. Or are you sending the message in plain XML which is a javax.jmx.TextMessage.

           

          eg if you send plain XML then JAXB can turn that XML into a JAXB object for you.

           

          If you send objects over JMS then make sure the JAXB classes are on both sides, eg on the producer and consumer sides. And that they are serializable compatible. eg usually the same version/JAR etc.

          • 2. Re: Can't produce JAXB object messages
            nicolas duminil Master

            I'm sending javax.jms.ObjectMessage. These objects classes are XJC generated and, since I didn't manage to get the JAXB binding generating "implements Serializable", I extended them in mine classes which ony implement serializable. I stored messages in a JMS queue after having initialized the object. The consumer retrieves messages but it finds them as if they weren't intialized. Both the producer and the consumer are in the same bundle deployed on Karaf.

             

            Instead of extending the JAXB classes I just copied their attributes in mine ones, provided the getters/setters, implement Serializable and removed extends ...

             

            This has solved the problem. But I don't understand why is that.

             

            Kind regards,

             

            Nicolas

            • 3. Re: Can't produce JAXB object messages
              Freeman(Yue) Fang Master

              Hi,

               

              I think this is just how java serialization works.

              I guess your jaxb object has some non-serializable field, If so, take a look at to get more details.

              Why not add JAXB binding  to generate "implements Serializable" jaxb object?

              http://stackoverflow.com/questions/95181/java-serialization-with-non-serializable-parts

               

              Freeman