How do we parse AppEngine URL-Safe Keys in the Google Cloud API?

4 views
Skip to first unread message

jcjones1515 via StackOverflow

unread,
Jan 12, 2017, 2:49:04 AM1/12/17
to google-appengin...@googlegroups.com

in the absence of a fix to the bug report that @snakecharmerb found, could you not base64 decode the string and tease out the pieces that you need to construct a Key via the Key.newBuilder method?

Certainly not ideal, but would get you around the issue.



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/41606795/how-do-we-parse-appengine-url-safe-keys-in-the-google-cloud-api/41607639#41607639

Joshua Fox via StackOverflow

unread,
Jan 12, 2017, 3:44:07 AM1/12/17
to google-appengin...@googlegroups.com

We have some URL-safe Datastore Keys that were created using in the AppEngine API, for example agx0cmFkZW9zLXRlc3RyHQsSEHVzZXIvTGVnYWxFbnRpdHkYgICAgIDu1AkM

These are parsed correctly in the AppEngine API, using com.google.appengine.api.datastore.KeyFactory.stringToKey(key)

However, in the Google Cloud API, com.google.cloud.datastore.Key.fromUrlSafe(key) always generates a parsing error as below.

Perhaps the URL-Safe string formats of the Google Cloud API was changed incompatibly, but we do need to be able to parse and also to generate the old format.

Ultimately this is a string-parsing task with no deep dependency on the libraries, so it should be possible to do with a simple code snippet.

How can we parse and generate such key strings using the Google Cloud API?

java.lang.IllegalArgumentException: Could not parse key
    at com.google.cloud.datastore.Key.fromUrlSafe(Key.java:205)
...
Caused by: com.google.protobuf.TextFormat$ParseException: 1:61: Expected "{".
    at com.google.protobuf.TextFormat$Tokenizer.parseException(TextFormat.java:1064)
    at com.google.protobuf.TextFormat$Tokenizer.consume(TextFormat.java:750)
    at com.google.protobuf.TextFormat$Parser.skipFieldMessage(TextFormat.java:1770)
    at com.google.protobuf.TextFormat$Parser.mergeField(TextFormat.java:1528)
    at com.google.protobuf.TextFormat$Parser.mergeField(TextFormat.java:1439)
    at com.google.protobuf.TextFormat$Parser.merge(TextFormat.java:1423)
    at com.google.protobuf.TextFormat$Parser.merge(TextFormat.java:1342)
    at com.google.protobuf.TextFormat.merge(TextFormat.java:1221)
    at com.google.cloud.datastore.Key.fromUrlSafe(Key.java:200)
    ... 1 more
Reply all
Reply to author
Forward
0 new messages