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

com.urbanairship.api.reports.parse.PushListingResponseReader Maven / Gradle / Ivy

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

package com.urbanairship.api.reports.parse;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.type.TypeReference;
import com.urbanairship.api.common.parse.APIParsingException;
import com.urbanairship.api.common.parse.JsonObjectReader;
import com.urbanairship.api.reports.model.PushInfoResponse;
import com.urbanairship.api.reports.model.PushListingResponse;

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

public final class PushListingResponseReader implements JsonObjectReader {

    private final PushListingResponse.Builder builder;

    public PushListingResponseReader() {
        this.builder = PushListingResponse.newBuilder();
    }

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

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

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy