private Key fromCacheKey(final String key) { return Key.fromUrlSafe(key); }
@Test public void testToAndFromUrlSafe() throws Exception { Key key = Key.newBuilder("d", "k", "n").build(); String urlSafe = key.toUrlSafe(); Key copy = Key.fromUrlSafe(urlSafe); assertEquals(key, copy); } }
/** */ @Override public Key deserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException, JsonProcessingException { final String text = jp.getText(); return Key.fromUrlSafe(text); } }
/** * Understands both the legacy format "ag1zfnZvb2Rvb2R5bmUwcgcLEgFCGAEM" and new format, * providing the key either way. */ @SneakyThrows public static com.google.cloud.datastore.Key fromUrlSafe(final String urlSafeKey) { if (urlSafeKey.startsWith("a")) { return KeyFormat.INSTANCE.parseOldStyleAppEngineKey(urlSafeKey); } else { return com.google.cloud.datastore.Key.fromUrlSafe(urlSafeKey); } } }
/** * Creates a new instance of <code>DefaultDatastoreKey</code>. * * @param encoded * the encoded string from which the key should be constructed. */ public DefaultDatastoreKey(String encoded) { this(Key.fromUrlSafe(encoded)); }