com.urbanairship.api.push.parse.notification.NotificationSerializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-client Show documentation
Show all versions of java-client Show documentation
The Urban Airship Java client library
/*
* Copyright (c) 2013-2016. Urban Airship and Contributors
*/
package com.urbanairship.api.push.parse.notification;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.urbanairship.api.push.model.DeviceType;
import com.urbanairship.api.push.model.notification.DevicePayloadOverride;
import com.urbanairship.api.push.model.notification.Notification;
import java.io.IOException;
import java.util.Map;
public class NotificationSerializer extends JsonSerializer {
@Override
public void serialize(Notification notification, JsonGenerator jsonGenerator, SerializerProvider provider) throws IOException {
jsonGenerator.writeStartObject();
if (notification.getAlert().isPresent()) {
jsonGenerator.writeStringField("alert", notification.getAlert().get());
}
for (Map.Entry entry : notification.getDeviceTypePayloadOverrides().entrySet()) {
jsonGenerator.writeObjectField(entry.getKey().getIdentifier(), entry.getValue());
}
if (notification.getActions().isPresent()) {
jsonGenerator.writeObjectField("actions", notification.getActions().get());
}
if (notification.getInteractive().isPresent()) {
jsonGenerator.writeObjectField("interactive", notification.getInteractive().get());
}
jsonGenerator.writeEndObject();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy