in src/main/scala/com/amazon/deequ/repository/AnalysisResultSerde.scala [500:543]
override def serialize(metric: Metric[_], t: Type,
context: JsonSerializationContext): JsonElement = {
val result = new JsonObject()
metric match {
case _ if metric.value.isFailure =>
throw new IllegalArgumentException(s"Unable to serialize failed metrics.")
case doubleMetric: DoubleMetric =>
result.addProperty("metricName", "DoubleMetric")
result.addProperty("entity", doubleMetric.entity.toString)
result.addProperty("instance", doubleMetric.instance)
result.addProperty("name", doubleMetric.name)
result.addProperty("value", doubleMetric.value.getOrElse(null).asInstanceOf[Double])
case histogramMetric: HistogramMetric =>
result.addProperty("metricName", "HistogramMetric")
result.addProperty(COLUMN_FIELD, histogramMetric.column)
result.addProperty("numberOfBins", histogramMetric.value.get.numberOfBins)
result.add("value", context.serialize(histogramMetric.value.get,
classOf[Distribution]))
case keyedDoubleMetric: KeyedDoubleMetric =>
result.addProperty("metricName", "KeyedDoubleMetric")
result.addProperty("entity", keyedDoubleMetric.entity.toString)
result.addProperty("instance", keyedDoubleMetric.instance)
result.addProperty("name", keyedDoubleMetric.name)
if (keyedDoubleMetric.value.isSuccess) {
val values = new JsonObject()
keyedDoubleMetric.value.get.foreach { case (key, value) =>
values.addProperty(key, value)
}
result.add("value", values)
}
case _ =>
throw new IllegalArgumentException(s"Unable to serialize metrics $metric.")
}
result
}