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

com.github.twitch4j.helix.interceptor.ContentClassificationStateListSerializer Maven / Gradle / Ivy

package com.github.twitch4j.helix.interceptor;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.github.twitch4j.eventsub.domain.ContentClassification;
import com.github.twitch4j.helix.domain.ChannelInformation;
import com.github.twitch4j.helix.domain.ContentClassificationState;
import org.jetbrains.annotations.ApiStatus;

import java.io.IOException;
import java.util.Collection;

/**
 * Serializes {@code Collection} within {@link com.github.twitch4j.helix.domain.ChannelInformation}
 * for {@link com.github.twitch4j.helix.TwitchHelix#updateChannelInformation(String, String, ChannelInformation)}
 * where {@link ContentClassification#MATURE_GAME} is not included in {@link ChannelInformation#getContentClassificationLabels()}
 * since this label is controlled by the game category (rather than the user).
 */
@ApiStatus.Internal
public class ContentClassificationStateListSerializer extends JsonSerializer> {
    @Override
    public void serialize(Collection value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
        if (value != null) {
            gen.writeStartArray();
            for (ContentClassificationState ccl : value) {
                if (ccl == null) continue;
                if (ccl.getId() == ContentClassification.MATURE_GAME) continue;
                gen.writeObject(ccl);
            }
            gen.writeEndArray();
        } else {
            gen.writeNull();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy