Converting last evaluated key Map to a Json and vice versa

Viewed 598

While doing pagination in dynamo db I want to send the last evaluated key to my client, so that he can give that same value next time while querying.

Last evaluated key is of type Map, I want to convert it to String and then send it to my client. Now while converting this string back to map I am getting conversion exceptions:

com.google.gson.JsonSyntaxException: java.io.EOFException

I was using Gson library for doing the operations. I believe this is a standard use case, any suggestions here?

1 Answers

Yes, you can use Gson library to parse it. Using Java, you can do so with the following code:

Gson gson = new Gson();    
gson.fromJson(YOUR_STRING_KEY, new TypeToken<Map<String, AttributeValue>>() {}.getType);

If you get an Exception, then the String key is not in the correct Json format.

Related