protected static final String PROPERTIES_TAG = "properties";
@Override
public Element deserialize(JsonElement json, Type typeOfT,
JsonDeserializationContext context) throws JsonParseException {
Element result = null;
ElementType type = ElementType.valueOfIgnoreCase(
json.getAsJsonObject().get(TYPE_TAG).getAsString());
Map<String, String> properties = context.deserialize(
json.getAsJsonObject().get(PROPERTIES_TAG), GsonFactory.STRING_MAP_TYPE);
if (FormElement.getFormElementTypes().contains(type)) {
result = new FormElement(type, properties);
} else if (type == ElementType.GADGET) {
result = new Gadget(properties);
} else if (type == ElementType.IMAGE) {
result = new Image(properties);
} else if (type == ElementType.ATTACHMENT) {
byte[] data = null;
String encodedData = properties.get(Attachment.DATA);
if (encodedData != null) {
try {
data = Base64.decodeBase64(encodedData.getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
throw new JsonParseException("Couldn't convert to utf-8", e);
}
}
result = new Attachment(properties, data);
} else if (type == ElementType.LINE) {
result = new Line(properties);
} else {
result = new Element(type, properties);
}
return result;
}