def anyValToJsValue()

in s2core/src/main/scala/org/apache/s2graph/core/JSONParser.scala [280:301]


  def anyValToJsValue(value: Any): Option[JsValue] = {
    try {
      val v = value match {
        case null => JsNull
        case l: Long => JsNumber(l)
        case i: Int => JsNumber(i)
        case s: Short => JsNumber(s.toInt)
        case b: Byte => JsNumber(b.toInt)
        case f: Float => JsNumber(f.toDouble)
        case d: Double => JsNumber(d)
        case bd: BigDecimal => if (bd.isValidLong) JsNumber(bd.toLong) else JsNumber(bd)
        case s: String => JsString(s)
        case b: Boolean => JsBoolean(b)
        case _ => throw new RuntimeException(s"$value, ${value.getClass.getName} is not supported data type.")
      }
      Option(v)
    } catch {
      case e: Exception =>
        logger.error(s"anyValToJsValue: $value", e)
        None
    }
  }