I've been using the JSON-RPC
library for some time now to write the server for my game, thus far I've only had a need to transport simple objects back to the client, but recently I've had a need send a collection of objects back. This is where I found that JSON-RPC falls short if you try to use the standard Java collections.
I've tried several things, first I used a Collection, which resulted in the following exception:
Caused by: java.lang.IllegalArgumentException: abstract class or interface not allowed : interface java.util.Collection
Then I thought if I used a concrete class, it would fix that, but alas, the following exception is thrown:
Caused by: java.lang.IllegalArgumentException: parametrized classes not allowed : class java.util.ArrayList
So what's a parametrized class? Well that's to do with Java Generics, the ArrayList I had was actually something like an ArrayList and the JSON-RPC library doesn't know how to handle that.
It looks like all of the Java collections now are parametrized, so using them will not work. The only thing I found that would work was to send an array of my objects instead. This is a bit messy since it means I have to allocate my array on the server side with a known size, with a collection I was just using lazy loading, which saved me some hassle.
So to sum up, my object that was being returned to the client had to change from this:
private List<MyOtherClass> otherClass;
private MyOtherClass otherClass;
A quick disclaimer...
Although I put in a great effort into researching all the topics I cover, mistakes can happen.
Use of any information from my blog posts should be at own risk and I do not hold any liability towards any information misuse or damages caused by following any of my posts.
All content and opinions expressed on this Blog are my own and do not represent the opinions of my employer (Oracle).
Use of any information contained in this blog post/article is subject to this disclaimer