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.
The code for this is available in the App Engine API distribution. It de/serializes a ProtoBuf Reference object.
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 and without any code specific to the App Engine API.
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