• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala read类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Scala中org.json4s.jackson.Serialization.read的典型用法代码示例。如果您正苦于以下问题:Scala read类的具体用法?Scala read怎么用?Scala read使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了read类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。

示例1: Segment

//设置package包名称以及导入依赖的类
package com.crystal
package models

// Kinesis
import stores.KinesisStream

// JSON
import org.json4s._
import org.json4s.jackson.JsonMethods._
import org.json4s.jackson.Serialization
import org.json4s.jackson.Serialization.{read, write}

// Rules
import rule_engine.rules.Rule

case class Segment(val name: String, rule: Rule) {
  import Segment._

  def containsUser(user: User): Boolean = {
    rule.fulfilledBy(user.toMap)
  }

  def alreadyContainedUser(user: User): Boolean = {
    val userWithoutNewEvents = User(user.id, user.persistedActions)
    rule.fulfilledBy(userWithoutNewEvents.toMap)
  }

  def publishUserEntrance(user: User) = {
    implicit val formats = Serialization.formats(ShortTypeHints(List(classOf[EnterSegmentEvent])))

    val event = EnterSegmentEvent(user.id, name)
    stream.put(user.id, write(event).getBytes("UTF-8"))
  }

  def publishUserExit(user: User) = {
    implicit val formats = Serialization.formats(ShortTypeHints(List(classOf[ExitSegmentEvent])))

    val event = ExitSegmentEvent(user.id, name)
    stream.put(user.id, write(event).getBytes("UTF-8"))
  }
}

object Segment {
  val config = AppConfig.load().get
  val stream = KinesisStream(config.outStreamName)

  case class EnterSegmentEvent(user_id: String, segment_name: String)
  case class ExitSegmentEvent(user_id: String, segment_name: String)
} 
开发者ID:crystal-project-inc,项目名称:streaming_user_segmentation,代码行数:50,代码来源:Segment.scala


示例2: TaskStatus

//设置package包名称以及导入依赖的类
package com.pagerduty.scheduler.model

import java.time.Instant
import org.json4s.DefaultFormats
import org.json4s.jackson.Serialization.{read, write}


case class TaskStatus(numberOfAttempts: Int, completionResult: CompletionResult, nextAttemptAt: Option[Instant]) {
  def isComplete = completionResult.isComplete

  implicit val formats = DefaultFormats + new TaskKeyTimeSerializer + new CompletionResultSerializer

  def toJson: String = write(this)
}

object TaskStatus {
  val Dropped: TaskStatus = {
    TaskStatus(numberOfAttempts = 0, CompletionResult.Dropped, nextAttemptAt = None)
  }
  val NeverAttempted: TaskStatus = {
    TaskStatus(numberOfAttempts = 0, CompletionResult.Incomplete, nextAttemptAt = None)
  }
  def successful(numberOfAttempts: Int): TaskStatus = {
    TaskStatus(numberOfAttempts, CompletionResult.Success, nextAttemptAt = None)
  }
  def failed(numberOfAttempts: Int): TaskStatus = {
    TaskStatus(numberOfAttempts, CompletionResult.Failure, nextAttemptAt = None)
  }

  implicit val formats = DefaultFormats + new TaskKeyTimeSerializer + new CompletionResultSerializer

  def fromJson(taskStatus: String): TaskStatus = read[TaskStatus](taskStatus)
} 
开发者ID:PagerDuty,项目名称:scheduler,代码行数:34,代码来源:TaskStatus.scala


示例3: TaskAttempt

//设置package包名称以及导入依赖的类
package com.pagerduty.scheduler.model

import java.time.Instant
import org.json4s.DefaultFormats
import org.json4s.jackson.Serialization.{read, write}


case class TaskAttempt(
    attemptNumber: Int,
    startedAt: Instant,
    finishedAt: Instant,
    taskResult: CompletionResult,
    taskResultUpdatedAt: Instant,
    exceptionClass: Option[String],
    exceptionMessage: Option[String],
    exceptionStackTrace: Option[String]) {
  implicit val formats = DefaultFormats + new TaskKeyTimeSerializer + new CompletionResultSerializer

  def toJson: String = write(this)
}

object TaskAttempt {
  def apply(
      attemptNumber: Int,
      startedAt: Instant,
      finishedAt: Instant,
      taskResult: CompletionResult,
      taskResultUpdatedAt: Instant,
      exception: Option[Throwable]
    ): TaskAttempt = {
    TaskAttempt(
      attemptNumber,
      startedAt,
      finishedAt,
      taskResult,
      taskResultUpdatedAt,
      exceptionClass = exception.map(_.getClass.getName),
      exceptionMessage = exception.map(_.getMessage),
      exceptionStackTrace = exception.map(_.getStackTraceString)
    )
  }

  implicit val formats = DefaultFormats + new TaskKeyTimeSerializer + new CompletionResultSerializer

  def fromJson(taskAttempt: String): TaskAttempt = read[TaskAttempt](taskAttempt)
} 
开发者ID:PagerDuty,项目名称:scheduler,代码行数:47,代码来源:TaskAttempt.scala


示例4: OrderTaggingEventAdapter

//设置package包名称以及导入依赖的类
package poc.persistence.write

import java.nio.charset.Charset

import akka.actor.ExtendedActorSystem
import akka.event.Logging
import akka.persistence.journal.{Tagged, WriteEventAdapter}
import org.json4s.DefaultFormats
import poc.persistence.events.{OrderCancelled, OrderInitialized}

class OrderTaggingEventAdapter(actorSystem: ExtendedActorSystem) extends WriteEventAdapter {

  private val log = Logging.getLogger(actorSystem, this)

  override def toJournal(event: Any): Any = event match {
    case e: OrderInitialized =>
      log.debug("tagging OrderInitialized event")
      Tagged(e, Set("UserEvent"))
    case e: OrderCancelled =>
      log.debug("tagged OrderCancelled event")
      Tagged(e, Set("UserEvent"))
  }

  override def manifest(event: Any): String = ""
}

import akka.serialization.Serializer

class EventSerialization(actorSystem: ExtendedActorSystem) extends Serializer {

  import org.json4s.jackson.Serialization.{read, write}

  private val log = Logging.getLogger(actorSystem, this)

  val UTF8: Charset = Charset.forName("UTF-8")

  implicit val formats = DefaultFormats

  // Completely unique value to identify this implementation of Serializer, used to optimize network traffic.
  // Values from 0 to 16 are reserved for Akka internal usage.
  // Make sure this does not conflict with any other kind of serializer or you will have problems
  override def identifier: Int = 90020001

  override def includeManifest = true

  override def fromBinary(bytes: Array[Byte], manifestOpt: Option[Class[_]]): AnyRef = {
    implicit val manifest = manifestOpt match {
      case Some(x) => Manifest.classType(x)
      case None => Manifest.AnyRef
    }
    val str = new String(bytes, UTF8)
    val result = read(str)
    result
  }

  override def toBinary(o: AnyRef): Array[Byte] = {
    val jsonString = write(o)
    val dat = write(o).getBytes(UTF8)
    dat
  }
} 
开发者ID:logicaalternativa,项目名称:akka-persistence-POC,代码行数:62,代码来源:Infrastructure.scala


示例5: WorldPipeline

//设置package包名称以及导入依赖的类
package springnz.sparkplug.examples

import org.apache.spark.rdd.RDD
import org.apache.spark.sql.DataFrame
import org.json4s._
import org.json4s.jackson.Serialization.read
import springnz.sparkplug.core._
import springnz.sparkplug.data.JdbcDataFrameSource
import springnz.sparkplug.examples.WorldDataTypes._

import scala.util.Try

object WorldPipeline {
  implicit val formats = DefaultFormats

}
trait WorldPipeline {
  import WorldPipeline._

  def dataSource: SparkOperation[DataFrame] = JdbcDataFrameSource("world", "Country")

  lazy val countriesOperation: SparkOperation[RDD[Country]] = for {
    dataFrame ? dataSource
  } yield {
    dataFrame.toJSON.mapWithFilter {
      jsonString ? Try { read[Country](jsonString) }.toOption
    }
  }
} 
开发者ID:springnz,项目名称:sparkplug-extras,代码行数:30,代码来源:WorldCountries.scala



注:本文中的org.json4s.jackson.Serialization.read类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala Enumerator类代码示例发布时间:2022-05-23
下一篇:
Scala GenericMutableRow类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap