forked from getsentry/sentry-java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SentryItemType.java
70 lines (60 loc) · 1.93 KB
/
SentryItemType.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package io.sentry;
import io.sentry.clientreport.ClientReport;
import io.sentry.protocol.SentryTransaction;
import java.io.IOException;
import java.util.Locale;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
@ApiStatus.Internal
public enum SentryItemType implements JsonSerializable {
Session("session"),
Event("event"), // DataCategory.Error
UserFeedback("user_report"), // Sentry backend still uses user_report
Attachment("attachment"),
Transaction("transaction"),
Profile("profile"),
ClientReport("client_report"),
ReplayEvent("replay_event"),
ReplayRecording("replay_recording"),
Unknown("__unknown__"); // DataCategory.Unknown
private final String itemType;
public static SentryItemType resolve(Object item) {
if (item instanceof SentryEvent) {
return Event;
} else if (item instanceof SentryTransaction) {
return Transaction;
} else if (item instanceof Session) {
return Session;
} else if (item instanceof ClientReport) {
return ClientReport;
} else {
return Attachment;
}
}
SentryItemType(final String itemType) {
this.itemType = itemType;
}
public String getItemType() {
return itemType;
}
public static @NotNull SentryItemType valueOfLabel(String itemType) {
for (SentryItemType sentryItemType : values()) {
if (sentryItemType.itemType.equals(itemType)) {
return sentryItemType;
}
}
return Unknown;
}
@Override
public void serialize(@NotNull JsonObjectWriter writer, @NotNull ILogger logger)
throws IOException {
writer.value(itemType);
}
static final class Deserializer implements JsonDeserializer<SentryItemType> {
@Override
public @NotNull SentryItemType deserialize(
@NotNull JsonObjectReader reader, @NotNull ILogger logger) throws Exception {
return SentryItemType.valueOfLabel(reader.nextString().toLowerCase(Locale.ROOT));
}
}
}