cloud.eppo.ufc.dto.adapters.EppoValueSerializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sdk-common-jvm Show documentation
Show all versions of sdk-common-jvm Show documentation
Eppo SDK for JVM shared library
package cloud.eppo.ufc.dto.adapters;
import cloud.eppo.api.EppoValue;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import java.io.IOException;
public class EppoValueSerializer extends StdSerializer {
protected EppoValueSerializer(Class t) {
super(t);
}
public EppoValueSerializer() {
this(null);
}
@Override
public void serialize(EppoValue src, JsonGenerator jgen, SerializerProvider provider)
throws IOException {
if (src.isBoolean()) {
jgen.writeBoolean(src.booleanValue());
}
if (src.isNumeric()) {
jgen.writeNumber(src.doubleValue());
}
if (src.isString()) {
jgen.writeString(src.stringValue());
}
if (src.isStringArray()) {
String[] arr = src.stringArrayValue().toArray(new String[0]);
jgen.writeArray(arr, 0, arr.length);
} else {
jgen.writeNull();
}
}
}