public JsonElement serialize(Element src, Type typeOfSrc, JsonSerializationContext context) {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty(TYPE_TAG, src.getType().toString());
JsonObject properties = new JsonObject();
if (src.isAttachment()) {
Attachment attachment = (Attachment) src;
if (attachment.hasData()) {
byte[] encodedData = Base64.encodeBase64(attachment.getData());
try {
properties.add(Attachment.DATA, new JsonPrimitive(
new String(encodedData, "UTF-8")));
} catch (UnsupportedEncodingException e) {
// this shouldn't happen, so let it slide.