-
-
Notifications
You must be signed in to change notification settings - Fork 69
/
ContentClassificationStateListSerializer.java
36 lines (33 loc) · 1.62 KB
/
ContentClassificationStateListSerializer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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<ContentClassificationState>} 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<Collection<ContentClassificationState>> {
@Override
public void serialize(Collection<ContentClassificationState> 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();
}
}
}