0

The GAE doc said:

Keys and values can be of any Serializable type or class

I use MultiKey as the key but after update my app, it gives me exception:

java.lang.IllegalArgumentException: Cannot use as a key: 'MultiKey[class com.xx.xx.xx, Key<?>(Domain("xxx.com")/AppUser(2001)), -1, {}, [-lastModified, ]]'
    at com.google.appengine.api.memcache.AsyncMemcacheServiceImpl.makePbKey(AsyncMemcacheServiceImpl.java:251)
    at com.google.appengine.api.memcache.AsyncMemcacheServiceImpl.doGet(AsyncMemcacheServiceImpl.java:294)
    at com.google.appengine.api.memcache.AsyncMemcacheServiceImpl.get(AsyncMemcacheServiceImpl.java:306)
    at com.google.appengine.api.memcache.MemcacheServiceImpl.get(MemcacheServiceImpl.java:49)

MultiKey is from apache commons-collections, which did implement Serializable

public class MultiKey
extends java.lang.Object
implements java.io.Serializable

Any ideas?

Thanks.

EDIT, the code is like below:

MemcacheService ms = MemcacheServiceFactory.getMemcacheService();
MultiKey key=new MultiKey(xx, xx, xx...);
ms.put( key, value );
...
Mike
  • 3,515
  • 10
  • 44
  • 67

1 Answers1

0

Maybe i got the idea, below is how gae serialize the key, it just write the object to byte array, so if one of the objects contained in the key(MultiKey in my situation) did not implement Serializable, this method will not work and throw exception, which is just my case.

     } else if (value instanceof Serializable) {
          flags = Flag.OBJECT;
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          ObjectOutputStream objOut = new ObjectOutputStream(baos);
          objOut.writeObject(value);
          objOut.close();
          bytes = baos.toByteArray();
     }
Mike
  • 3,515
  • 10
  • 44
  • 67