Skip to content

Commit 202e4f0

Browse files
Updated to use new EppoValue.getType()
1 parent 4d04281 commit 202e4f0

File tree

2 files changed

+32
-18
lines changed

2 files changed

+32
-18
lines changed

src/main/java/cloud/eppo/api/EppoValue.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import java.util.Objects;
77

88
public class EppoValue {
9-
public final EppoValueType type;
9+
protected final EppoValueType type;
1010
protected Boolean boolValue;
1111
protected Double doubleValue;
1212
protected String stringValue;
@@ -92,6 +92,10 @@ public boolean isStringArray() {
9292
return type == EppoValueType.ARRAY_OF_STRING;
9393
}
9494

95+
public EppoValueType getType() {
96+
return type;
97+
}
98+
9599
@Override
96100
public String toString() {
97101
switch (this.type) {
Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package cloud.eppo.ufc.dto.adapters;
22

33
import cloud.eppo.api.EppoValue;
4+
import cloud.eppo.ufc.dto.EppoValueType;
5+
46
import com.fasterxml.jackson.core.JsonGenerator;
57
import com.fasterxml.jackson.databind.SerializerProvider;
68
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
@@ -18,23 +20,31 @@ public EppoValueSerializer() {
1820
@Override
1921
public void serialize(EppoValue src, JsonGenerator jgen, SerializerProvider provider)
2022
throws IOException {
21-
switch (src.type) {
22-
case NULL:
23-
jgen.writeNull();
24-
break;
25-
case BOOLEAN:
26-
jgen.writeBoolean(src.booleanValue());
27-
break;
28-
case NUMBER:
29-
jgen.writeNumber(src.doubleValue());
30-
break;
31-
case STRING:
32-
jgen.writeString(src.stringValue());
33-
break;
34-
case ARRAY_OF_STRING:
35-
String[] arr = src.stringArrayValue().toArray(new String[0]);
36-
jgen.writeArray(arr, 0, arr.length);
37-
break;
23+
final EppoValueType type = src.getType();
24+
if (type == null) {
25+
// this should never happen, but if it does,
26+
// we need to write something so that we're valid JSON
27+
// so a null value is safest.
28+
jgen.writeNull();
29+
} else {
30+
switch (src.getType()) {
31+
case NULL:
32+
jgen.writeNull();
33+
break;
34+
case BOOLEAN:
35+
jgen.writeBoolean(src.booleanValue());
36+
break;
37+
case NUMBER:
38+
jgen.writeNumber(src.doubleValue());
39+
break;
40+
case STRING:
41+
jgen.writeString(src.stringValue());
42+
break;
43+
case ARRAY_OF_STRING:
44+
String[] arr = src.stringArrayValue().toArray(new String[0]);
45+
jgen.writeArray(arr, 0, arr.length);
46+
break;
47+
}
3848
}
3949
}
4050
}

0 commit comments

Comments
 (0)