8 Replies Latest reply on Jul 6, 2012 9:15 AM by jfuerth

    Is there a way to let Errai genernate the marshaller for portable object's array?

    smile365

      When use Errai 2.0.1, we encounter a issue: When we send portable object's array as message body, Errai report "cannot find the marshaller for [Lclassname" exception.

       

      Is there a way to let Errai genernate the marshaller for portable object's array?

       

      There's no such issue in Errai 1.3.x.

        • 1. Re: Is there a way to let Errai genernate the marshaller for portable object's array?
          smile365

          Anyone can give me some ideas?

          • 2. Re: Is there a way to let Errai genernate the marshaller for portable object's array?
            navigateur

            Is your array field public? I had trouble with a public ArrayList of portable objects and removing the "public" modifier helped for now. I submitted a bug report for that here: https://issues.jboss.org/browse/ERRAI-329.

            • 3. Re: Is there a way to let Errai genernate the marshaller for portable object's array?
              smile365

              Thanks for your reply.

               

              My situation is not the same.

               

              I want to send @Portable object's array as message body.

               

              For example class Anmimal is marked as @Portable,

               

              @Portable

              public class Animal {

                ....

              }

               

               

              the code snippet for sending message:

               

              Anmial[] animals = new Animal[2];

              animals[0] = new Animal(...);

              animals[1] = new Animal(...);

               

              MessageBuilder.createMessage()

               

                    .toSubject("HelloWorldClient")

               

                    .signalling()   

               

                    .with("text", animals);

               

                    .noErrorHandling()

               

                    .sendNowWith(dispatcher);

               

              Errai report a RuntimeException which indicate "no marshaller for [LAnimal".

              • 4. Re: Is there a way to let Errai genernate the marshaller for portable object's array?
                nva

                I had no problems sending my own, portable instances as lists. Perhaps if you sent it as an ArrayList, instead of an array. On the client side this shouldn cause a problem. On the server-side you can easily convert between arrays and lists if you have to. Hope this helps.

                • 5. Re: Is there a way to let Errai genernate the marshaller for portable object's array?
                  smile365

                  Thanks for your reply.

                   

                  I gived it a try(converted it to ArrayList), but it didn't work. It also reported a RuntimeException which indicate "no marshaller available for [LAnimal".

                   

                  Can you show me  some sample code for this?  Thanks.

                  • 6. Re: Is there a way to let Errai genernate the marshaller for portable object's array?
                    jfuerth

                    We've confirmed that this is a bug in Errai 2.0. The problem is, Errai needs to specifically generate additional marshalling code for arrays. Since this can be somewhat expensive in terms of the size of your application's JavaScript payload, Errai avoids generating array marshallers for array types it doesn't think you're using.

                     

                    Fortunately, there are several workarounds:

                     

                    First, Valentin's tip of using a List rather than an array should work fine:

                     

                    Instead of

                     

                    Anmial[] animals = new Animal[2];

                    animals[0] = new Animal(...);

                    animals[1] = new Animal(...);

                     

                    MessageBuilder.createMessage()

                          .toSubject("HelloWorldClient")

                          .signalling()  

                          .with("text", animals);

                          .noErrorHandling()

                          .sendNowWith(dispatcher);

                     

                    try

                     

                    List<Anmial> animals = new ArrayList<Animal>();

                    animals.add(new Animal(...));

                    animals.add(new Animal(...));

                     

                    MessageBuilder.createMessage()

                          .toSubject("HelloWorldClient")

                          .signalling()  

                          .with("text", animals);

                          .noErrorHandling()

                          .sendNowWith(dispatcher);

                     

                     

                    Secondly, you could stick with the array (as in your original example) but trick the Errai marshalling system into generating a marshaller for Animal[] by declaring a field of type Animal[] on a portable class:

                     

                    /**

                    * This class is not used in the application. It's just a container for array types that we want to be able to marshal directly using Errai.

                    */

                    @Portable

                    public class DummyWorkaroundClass {

                      private Animal[] animalArray;

                    }

                     

                    Note that if you wanted to marshal a 2-dimensional array of Animals, you would have to create another field of type Animal[][].

                     

                    Hope that helps!

                     

                    Jonathan

                     

                    PS: we did try to fix this so that you don't need to employ any workarounds, but it appears to be more-or-less impossible to dynamically create an array of some type given either an object of that type or its Class object. So don't say we didn't try.

                    1 of 1 people found this helpful
                    • 7. Re: Is there a way to let Errai genernate the marshaller for portable object's array?
                      smile365

                      Thanks for your reply.

                       

                      I gived it a try.

                       

                      only

                      List<Anmial> animals = new ArrayList<Animal>();

                      animals.add(new Animal(...));

                      animals.add(new Animal(...));

                       

                      can work.

                       

                       

                      Anmial[] animals = new Animal[2];

                      animals[0] = new Animal(...);

                      animals[1] = new Animal(...);

                       

                      Arrays.asList(animals) or new ArrayList(Arrays.asList(animals)) doesn't work.

                       

                      PS: I think that Errai needs not to specifically generate additional marshalling code for arrays, too. Errai Marshalling framework should handle this scenario.

                      • 8. Re: Is there a way to let Errai genernate the marshaller for portable object's array?
                        jfuerth

                        Did you try the second workaround (of creating a dummy @Portable class with a field of type Animal[])? I verified that this does work.

                         

                        PS: I think that Errai needs not to specifically generate additional marshalling code for arrays, too. Errai Marshalling framework should handle this scenario.

                         

                        Agreed. If you can show us how to create an array in GWT with an arbitrary number of dimensions, we can do the rest. Yesterday, two of us spent 6 hours each on a refactoring that makes this possible. However, there is one critical operation that appears impossible in GWT: we haven't figured out how to create an array of a type that is only known at runtime. This type of dynamic creation of things is intentionally impossible in GWT, of course. But we do suspect it might be possible for arrays. If you know how, please let us know! All it takes at this point is to plug in that "magic incantation" to create the array. All the other work within Errai is complete. Until then, though, specific marshallers for array types are going to be required.

                         

                        -Jonathan