All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cloud.eppo.ufc.dto.adapters.EppoValueSerializer Maven / Gradle / Ivy

There is a newer version: 3.3.2
Show newest version
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();
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy