The JsonElement#getAsString method throws an exception by default. Use Gson#toJson to convert the object into a json string.