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

com.urbanairship.api.experiments.parse.VariantSerializer Maven / Gradle / Ivy

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

package com.urbanairship.api.experiments.parse;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.urbanairship.api.experiments.model.Variant;

import java.io.IOException;

public class VariantSerializer extends JsonSerializer {

    @Override
    public void serialize(Variant variant, JsonGenerator jgen, SerializerProvider provider) throws IOException {
        jgen.writeStartObject();

        if (variant.getName().isPresent()) {
            jgen.writeObjectField("name", variant.getName().get());
        }
        if (variant.getDescription().isPresent()) {
            jgen.writeObjectField("description", variant.getDescription().get());
        }
        if (variant.getSchedule().isPresent()) {
            jgen.writeObjectField("schedule", variant.getSchedule().get());
        }
        if (variant.getWeight().isPresent()) {
            jgen.writeObjectField("weight", variant.getWeight().get());
        }
        jgen.writeObjectField("push", variant.getVariantPushPayload());

        jgen.writeEndObject();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy