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

com.urbanairship.api.customevents.parse.CustomEventBodySerializer Maven / Gradle / Ivy

The newest version!
package com.urbanairship.api.customevents.parse;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.urbanairship.api.customevents.model.CustomEventBody;

import java.io.IOException;

public class CustomEventBodySerializer extends JsonSerializer {

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

        jgen.writeStringField("name", body.getName());

        if (body.getSessionId().isPresent()) {
            jgen.writeStringField("session_id", body.getSessionId().get());
        }
        if (body.getInteractionId().isPresent()) {
            jgen.writeStringField("interaction_id", body.getInteractionId().get());
        }

        if (body.getInteractionType().isPresent()) {
            jgen.writeStringField("interaction_type", body.getInteractionType().get());
        }

        if (body.getTransaction().isPresent()) {
            jgen.writeStringField("transaction", body.getTransaction().get());
        }

        if (body.getProperties().isPresent()) {
            jgen.writeObjectField("properties", body.getProperties().get());
        }

        if (body.getValue().isPresent()) {
            jgen.writeObjectField("value", body.getValue().get());
        }

        jgen.writeEndObject();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy