map base64 string as object with google gson

533 views
Skip to first unread message

Neeli

unread,
Sep 30, 2011, 9:31:56 PM9/30/11
to google-gson
Hi,

I am using gson library to parse json strings and convert them into my
java objects. I am trying to post a small image object as a base64
encoded string via json. On the server side, I map the json string to
my java object where the type is specified as "Blob" object which is
Blob class in google appengine datastore library. The end goal is to
post a small binary image file from my mobile client to google
appengine datastore.

Ex: "customImages":
[{"image":"VGhpcyBpcyBhIHRlc3Qgc3RyaW5nLiBUaGlzIGlzIGEgdGVzdCBzdHJpbmcu","id":"homeimg"}]

and it's mapped to List<HashMap<String, Blob>> in my java class. Blob
is a google datastore API class. I cannot use "String" as a value due
to size limitation. I have to use a Blob datatype to store the image
object.

com.google.gson.JsonParseException: Expecting object found:
"VGhpcyBpcyBhIHRlc3Qgc3RyaW5nLiBUaGlzIGlzIGEgdGVzdCBzdHJpbmcu"
at
com.google.gson.JsonObjectDeserializationVisitor.visitFieldUsingCustomHandler(JsonObjectDeserializationVisitor.java:
100)
at
com.google.gson.ReflectingFieldNavigator.visitFieldsReflectively(ReflectingFieldNavigator.java:
63)
at com.google.gson.ObjectNavigator.accept(ObjectNavigator.java:120)
at
com.google.gson.JsonDeserializationContextDefault.fromJsonPrimitive(JsonDeserializationContextDefault.java:
85)
at
com.google.gson.JsonDeserializationContextDefault.deserialize(JsonDeserializationContextDefault.java:
56)
at com.google.gson.MapTypeAdapter.deserialize(MapTypeAdapter.java:68)

Is there a way I can add my own handler and allow gson to get past
this?

Reply all
Reply to author
Forward
0 new messages