org.json4s.JsonAST Scala Examples
The following examples show how to use org.json4s.JsonAST.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
Example 1
Source File: LogAnalyticsListenerSink.scala From spark-monitoring with MIT License | 5 votes |
package org.apache.spark.listeners.sink.loganalytics import com.microsoft.pnp.client.loganalytics.{LogAnalyticsClient, LogAnalyticsSendBufferClient} import org.apache.spark.SparkConf import org.apache.spark.internal.Logging import org.apache.spark.listeners.sink.SparkListenerSink import org.json4s.JsonAST import org.json4s.jackson.JsonMethods.compact import scala.util.control.NonFatal class LogAnalyticsListenerSink(conf: SparkConf) extends SparkListenerSink with Logging { private val config = new LogAnalyticsListenerSinkConfiguration(conf) protected lazy val logAnalyticsBufferedClient = new LogAnalyticsSendBufferClient( new LogAnalyticsClient( config.workspaceId, config.secret), config.logType ) override def logEvent(event: Option[JsonAST.JValue]): Unit = { try { event match { case Some(j) => { val jsonString = compact(j) logDebug(s"Sending event to Log Analytics: ${jsonString}") logAnalyticsBufferedClient.sendMessage(jsonString, "SparkEventTime") } case None => } } catch { case NonFatal(e) => logError(s"Error sending to Log Analytics: $e") } } }
Example 2
Source File: BitSerializer.scala From NSDb with Apache License 2.0 | 5 votes |
package io.radicalbit.nsdb.web import io.radicalbit.nsdb.common._ import io.radicalbit.nsdb.common.protocol.Bit import org.json4s.JsonAST.{JDouble, JField, JInt, JLong} import org.json4s.{CustomSerializer, JObject, JString, JsonAST} case object BitSerializer extends CustomSerializer[Bit]( _ => ( { case _ => throw new IllegalAccessException( "BitSerializer can be used only for serialization and not for deserialization") }, { case bit: Bit => def extractJValue(nsdbType: NSDbType): JsonAST.JValue = { nsdbType match { case NSDbDoubleType(rawValue) => JDouble(rawValue) case NSDbIntType(rawValue) => JInt(rawValue) case NSDbLongType(rawValue) => JLong(rawValue) case NSDbStringType(rawValue) => JString(rawValue) } } JObject( List( JField("timestamp", JLong(bit.timestamp)), JField("value", extractJValue(bit.value)), JField("dimensions", JObject(bit.dimensions.map { case (k, v) => JField(k, extractJValue(v)) }.toList)), JField("tags", JObject(bit.tags.map { case (k, v) => JField(k, extractJValue(v)) }.toList)) ) ) } ))