All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.urbanairship.api.location.parse.LocationViewReader Maven / Gradle / Ivy

There is a newer version: 9.5.0
Show newest version
/*
 * Copyright (c) 2013-2016.  Urban Airship and Contributors
 */

package com.urbanairship.api.location.parse;

import com.urbanairship.api.common.parse.APIParsingException;
import com.urbanairship.api.common.parse.JsonObjectReader;
import com.urbanairship.api.location.model.LocationView;
import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.type.TypeReference;

import java.io.IOException;
import java.util.List;

public class LocationViewReader implements JsonObjectReader {

    private final LocationView.Builder builder;

    public LocationViewReader() {
        this.builder = LocationView.newBuilder();
    }

    public void readBounds(JsonParser jsonParser) throws IOException {
        builder.setBounds((List) jsonParser.readValueAs(new TypeReference>() {
        }));
    }

    public void readCentroid(JsonParser jsonParser) throws IOException {
        builder.setCentroid((List) jsonParser.readValueAs(new TypeReference>() {
        }));
    }

    public void readId(JsonParser jsonParser) throws IOException {
        builder.setLocationId(jsonParser.readValueAs(String.class));
    }

    public void readPropertyJSONNode(JsonParser jsonParser) throws IOException {
        JsonNode jsonNode = jsonParser.readValueAsTree();
        builder.setPropertiesNode(jsonNode);
    }

    public void readType(JsonParser jsonParser) throws IOException {
        builder.setLocationType(jsonParser.readValueAs(String.class));
    }

    @Override
    public LocationView validateAndBuild() throws IOException {
        try {
            return builder.build();
        } catch (Exception e) {
            throw new APIParsingException(e.getMessage(), e);
        }
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy