Reputation: 384
I had tried with the below way and got failed,
Query query = new Query("Users");
List<Entity> results = datastore.prepare(query).asList(FetchOptions.Builder.withLimit(PAGE_SIZE));
for (Entity user : results){
Key key = user.getKey();
System.out.println(key); // here am getting as Users(151),Users(152)...
From here am passing the "Key" as request parameter to a servlet.
In My Servlet,
String keyString = req.getParameter("key");
Key key = KeyFactory.stringToKey(keyString);
datastore.delete(key);
the error says "Cannot parse: Users(151)==" and the line of error is " Key key = KeyFactory.stringToKey(keyString);"
Can anyone suggest me an idea,
Your help will be appreciated.
Upvotes: 0
Views: 680
Reputation: 80340
Instead of passing Key
as java objects to servlet, you should use this snippet to serialize
String encodedKey = KeyFactory.keyToString(key)
and this to deserialize
Key key = KeyFactory.stringToKey(encodedKey)
Upvotes: 2