use of co.aurasphere.botmill.fb.model.outcoming.payload.PayloadType in project fb-botmill by BotMill.
the class AttachmentDeserializer method deserialize.
/*
* (non-Javadoc)
*
* @see
* com.google.gson.JsonDeserializer#deserialize(com.google.gson.JsonElement,
* java.lang.reflect.Type, com.google.gson.JsonDeserializationContext)
*/
public Attachment deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
Attachment attachment = delegateGson.fromJson(json, Attachment.class);
AttachmentType type = attachment.getType();
Class<? extends Payload> payloadClass = null;
JsonElement payloadJson = json.getAsJsonObject().get("payload");
switch(type) {
case AUDIO:
case FILE:
case IMAGE:
case VIDEO:
payloadClass = UrlPayload.class;
break;
case LOCATION:
payloadClass = QuickReplyLocationPayload.class;
break;
case FALLBACK:
// nothing.
break;
case TEMPLATE:
// In case of a template I need to check which one to instantiate.
String payloadTypeString = payloadJson.getAsJsonObject().get("template_type").getAsString();
PayloadType templateType = PayloadType.valueOf(payloadTypeString.toUpperCase());
switch(templateType) {
case AIRLINE_BOARDINGPASS:
payloadClass = AirlineBoardingPassTemplatePayload.class;
break;
case AIRLINE_CHECKIN:
payloadClass = AirlineCheckinTemplatePayload.class;
break;
case AIRLINE_ITINERARY:
payloadClass = AirlineItineraryTemplatePayload.class;
break;
case AIRLINE_UPDATE:
payloadClass = AirlineFlightUpdateTemplatePayload.class;
break;
case BUTTON:
payloadClass = ButtonTemplatePayload.class;
break;
case GENERIC:
payloadClass = GenericTemplatePayload.class;
break;
case LIST:
payloadClass = ListTemplatePayload.class;
break;
case RECEIPT:
payloadClass = ReceiptTemplatePayload.class;
break;
}
break;
}
Payload payload = context.deserialize(payloadJson, payloadClass);
attachment.setPayload(payload);
return attachment;
}
Aggregations