-
-
Notifications
You must be signed in to change notification settings - Fork 468
Expand file tree
/
Copy pathSentryLogEventAttributeValue.java
More file actions
116 lines (97 loc) · 3.22 KB
/
SentryLogEventAttributeValue.java
File metadata and controls
116 lines (97 loc) · 3.22 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package io.sentry;
import io.sentry.vendor.gson.stream.JsonToken;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public final class SentryLogEventAttributeValue implements JsonUnknown, JsonSerializable {
private @NotNull String type;
private @Nullable Object value;
private @Nullable Map<String, Object> unknown;
public SentryLogEventAttributeValue(final @NotNull String type, final @Nullable Object value) {
this.type = type;
if (value != null && type.equals("string")) {
this.value = value.toString();
} else {
this.value = value;
}
}
public SentryLogEventAttributeValue(
final @NotNull SentryAttributeType type, final @Nullable Object value) {
this(type.apiName(), value);
}
public @NotNull String getType() {
return type;
}
public @Nullable Object getValue() {
return value;
}
// region json
public static final class JsonKeys {
public static final String TYPE = "type";
public static final String VALUE = "value";
}
@Override
@SuppressWarnings("JdkObsolete")
public void serialize(final @NotNull ObjectWriter writer, final @NotNull ILogger logger)
throws IOException {
writer.beginObject();
writer.name(JsonKeys.TYPE).value(logger, type);
writer.name(JsonKeys.VALUE).value(logger, value);
if (unknown != null) {
for (String key : unknown.keySet()) {
Object value = unknown.get(key);
writer.name(key).value(logger, value);
}
}
writer.endObject();
}
@Override
public @Nullable Map<String, Object> getUnknown() {
return unknown;
}
@Override
public void setUnknown(final @Nullable Map<String, Object> unknown) {
this.unknown = unknown;
}
public static final class Deserializer implements JsonDeserializer<SentryLogEventAttributeValue> {
@SuppressWarnings("unchecked")
@Override
public @NotNull SentryLogEventAttributeValue deserialize(
final @NotNull ObjectReader reader, final @NotNull ILogger logger) throws Exception {
@Nullable Map<String, Object> unknown = null;
@Nullable String type = null;
@Nullable Object value = null;
reader.beginObject();
while (reader.peek() == JsonToken.NAME) {
final String nextName = reader.nextName();
switch (nextName) {
case JsonKeys.TYPE:
type = reader.nextStringOrNull();
break;
case JsonKeys.VALUE:
value = reader.nextObjectOrNull();
break;
default:
if (unknown == null) {
unknown = new HashMap<>();
}
reader.nextUnknown(logger, unknown, nextName);
break;
}
}
reader.endObject();
if (type == null) {
String message = "Missing required field \"" + JsonKeys.TYPE + "\"";
Exception exception = new IllegalStateException(message);
logger.log(SentryLevel.ERROR, message, exception);
throw exception;
}
final SentryLogEventAttributeValue logEvent = new SentryLogEventAttributeValue(type, value);
logEvent.setUnknown(unknown);
return logEvent;
}
}
// endregion json
}