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

com.urbanairship.api.templates.parse.TemplateVariableReader Maven / Gradle / Ivy

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

package com.urbanairship.api.templates.parse;

import com.fasterxml.jackson.core.JsonParser;
import com.urbanairship.api.common.parse.APIParsingException;
import com.urbanairship.api.common.parse.JsonObjectReader;
import com.urbanairship.api.templates.model.TemplateVariable;

import java.io.IOException;

public class TemplateVariableReader implements JsonObjectReader {
    private final TemplateVariable.Builder builder;

    public TemplateVariableReader() {
        this.builder = TemplateVariable.newBuilder();
    }

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

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

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

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

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy