@Override public Element deserialize(JsonElement jsonElement, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject json = jsonElement.getAsJsonObject(); String type = json.get(TYPE_TAG).getAsString(); if (ElementType.IMAGE.name().equals(type)) { JsonObject properties = json.getAsJsonObject(PROPERTIES_TAG); if (!properties.has(Image.URL)) { json.addProperty(TYPE_TAG, ElementType.ATTACHMENT.name()); } } return super.deserialize(json, typeOfT, context); }
ElementGsonAdaptor elementGsonAdaptor = new ElementGsonAdaptor(); GsonBuilder builder = new GsonBuilder() .setExclusionStrategies(new NonSerializableExclusionStrategy())
@Override public JsonElement serialize(Element src, Type typeOfSrc, JsonSerializationContext context) { if (src.getType() == ElementType.ATTACHMENT) { src = new Element(ElementType.IMAGE, createImageProperties(src.getProperties())); } return super.serialize(src, typeOfSrc, context); }