Search in sources :

Example 1 with PostalAddress

use of com.google.api.services.actions_fulfillment.v2.model.PostalAddress in project dialogflow-transactions-java by actions-on-google.

the class LocationDeserializer method deserialize.

@Override
public Location deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    JsonObject jsonObject = json.getAsJsonObject();
    Location location = new Location();
    JsonElement city = jsonObject.get("city");
    JsonElement coordinates = jsonObject.get("coordinates");
    JsonElement name = jsonObject.get("name");
    JsonElement notes = jsonObject.get("notes");
    JsonElement phoneNumber = jsonObject.get("phoneNumber");
    JsonElement placeId = jsonObject.get("placeId");
    JsonElement zipCode = jsonObject.get("zipCode");
    JsonElement formattedAddress = jsonObject.get("formattedAddress");
    JsonElement postalAddress = jsonObject.get("postalAddress");
    if (city != null) {
        location.setCity(city.getAsString());
    }
    if (name != null) {
        location.setName(name.getAsString());
    }
    if (notes != null) {
        location.setNotes(notes.getAsString());
    }
    if (phoneNumber != null) {
        location.setPhoneNumber(phoneNumber.getAsString());
    }
    if (placeId != null) {
        location.setPlaceId(placeId.getAsString());
    }
    if (zipCode != null) {
        location.setZipCode(zipCode.getAsString());
    }
    if (formattedAddress != null) {
        location.setFormattedAddress(formattedAddress.getAsString());
    }
    if (postalAddress != null) {
        PostalAddress address = context.deserialize(postalAddress.getAsJsonObject(), PostalAddress.class);
        location.setPostalAddress(address);
    }
    if (coordinates != null) {
        LatLng coords = context.deserialize(coordinates.getAsJsonObject(), LatLng.class);
        location.setCoordinates(coords);
    }
    return location;
}
Also used : PostalAddress(com.google.api.services.actions_fulfillment.v2.model.PostalAddress) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) LatLng(com.google.api.services.actions_fulfillment.v2.model.LatLng) Location(com.google.api.services.actions_fulfillment.v2.model.Location)

Aggregations

LatLng (com.google.api.services.actions_fulfillment.v2.model.LatLng)1 Location (com.google.api.services.actions_fulfillment.v2.model.Location)1 PostalAddress (com.google.api.services.actions_fulfillment.v2.model.PostalAddress)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1