-
1. Re: Is there a way to let Errai genernate the marshaller for portable object's array?
smile365 Jul 5, 2012 3:09 AM (in response to 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 Jul 5, 2012 7:16 AM (in response to smile365)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 Jul 5, 2012 7:42 AM (in response to navigateur)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 Jul 5, 2012 10:23 AM (in response to smile365)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 Jul 5, 2012 10:14 PM (in response to nva)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 Jul 5, 2012 11:30 PM (in response to smile365)1 of 1 people found this helpfulWe'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.
-
7. Re: Is there a way to let Errai genernate the marshaller for portable object's array?
smile365 Jul 6, 2012 4:15 AM (in response to jfuerth)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 Jul 6, 2012 9:15 AM (in response to smile365)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