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

Scala OWrites类代码示例

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

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



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

示例1: OauthCode

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


import org.joda.time.{DateTime, Duration}
import play.api.libs.functional.syntax._
import play.api.libs.json.{JsPath, Json, OWrites, Reads}

import scala.util.Random



case class OauthCode(code : String, user: User, client : OauthClient) {
  val created = new DateTime(new java.util.Date())

  // currently codes are valid for one day
  def isExpired : Boolean = created.plus(new Duration(24L*60L*60L*1000L)).isBeforeNow
}

object OauthCode {
  def apply(user: User, client: OauthClient) : OauthCode = OauthCode(Random.alphanumeric.take(100).mkString, user, client)
//  implicit val oauthCodeJsonFormat = Json.format[OauthCode]
  implicit val profileWrites : OWrites[OauthCode] = (
    (JsPath \ "code").write[String] and
      (JsPath \ "user").write[User] and
      (JsPath \ "client").write[OauthClient]
    )(unlift(OauthCode.unapply))
  implicit val profileReads : Reads[OauthCode] = (
    (JsPath \ "code").read[String] and
      (JsPath \ "user").read[User] and
      (JsPath \ "client").read[OauthClient]
    )((code, user, client) => OauthCode(code, user, client))
} 
开发者ID:Viva-con-Agua,项目名称:drops,代码行数:33,代码来源:OauthCode.scala


示例2: View

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

import play.api.libs.json.{Json, OWrites, Reads}

sealed trait View {

}

object View {
  case class Gravity(x: Double, y: Double, z: Double, userId: Long, name: String) extends View
  case class Message(message: String, userId: Long, name: String) extends View
  case class Event(value: String, userId: Long, name: String) extends View

  trait JsonReader {
    implicit val testReader: Reads[Message] = Json.reads[Message]
  }
  trait JsonWriter {
    implicit val testWriter: OWrites[Message] = Json.writes[Message]
    implicit val eventWriter: OWrites[Event] = Json.writes[Event]
    implicit val gravityWriter = Json.writes[Gravity]
  }
} 
开发者ID:Augment8,项目名称:slot,代码行数:23,代码来源:View.scala


示例3: Envelope

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

import play.api.libs.json.{JsValue, Json, OWrites, Reads}

sealed trait User {

}

case class Envelope(`type`: String,value: JsValue)

case class ChangeName(name: String) extends User
case class PressButton(value: String) extends User
case class ReleaseButton(value: String) extends User
case class SessionId(sessionId: Long) extends User
case class Gravity(x: Double, y: Double, z: Double) extends User
case class Test(message: String) extends User

trait JsonFormat {
  implicit val envelopeJsonRead: Reads[Envelope] = Json.reads[Envelope]

  implicit val sessionIdJsonRead: Reads[SessionId] = Json.reads[SessionId]
  implicit val sessionIdJsonWrite: OWrites[SessionId] = Json.writes[SessionId]
  implicit val gravityJsonRead: Reads[Gravity] = Json.reads[Gravity]
  implicit val testJsonWrite: OWrites[Test] = Json.writes[Test]
  implicit val testJsonRead: Reads[Test] = Json.reads[Test]
  implicit val changeNameJsonRead: Reads[ChangeName] = Json.reads[ChangeName]
  implicit val pressButtonJsonRead: Reads[PressButton] = Json.reads[PressButton]
  implicit val releaseButtonJsonRead: Reads[ReleaseButton] = Json.reads[ReleaseButton]
} 
开发者ID:Augment8,项目名称:slot,代码行数:30,代码来源:User.scala


示例4: ServiceController

//设置package包名称以及导入依赖的类
package controllers


import api.sharecare.events.aws.AWSConfigs
import com.google.inject.Inject
import com.sharecare.lib.play.phr.controllers.PHRController
import com.sharecare.lib.play.phr.queryparams.QueryParameters
import com.sharecare.lib.play.phr.repository.PHRRepository
import com.sharecare.sdk.sso.play.Auth
import com.sharecare.sdk.sso.play.models.{Maskable, SecureMask}
import model.{SocialConverters, SocialIn, SocialPersistence, SocialResponse}
import play.api.Configuration
import play.api.libs.json.{Json, OWrites, Reads}
import play.api.libs.ws.WSClient


class ServiceController  @Inject() (repo: PHRRepository[SocialIn, SocialPersistence, SocialResponse],
                                    auth: Auth,
                                    config: Configuration,
                                    awsConfig: AWSConfigs,
                                    ws: WSClient)
  extends PHRController[QueryParameters, SocialIn, SocialPersistence, SocialResponse](repo, auth, config, awsConfig, ws) {
  import com.sharecare.lib.play.phr.models.serialization.PhrFormats._
  import com.sharecare.lib.play.phr.controllers.ResultHelpers._
  import com.sharecare.lib.play.errors.serialization.ErrorJsonFormats._

  override implicit def P_Writes: OWrites[SocialIn] =  Json.writes[SocialIn]

  override implicit def R_Writes: OWrites[SocialResponse] = Json.writes[SocialResponse]

  override implicit def In_Reads: Reads[SocialIn] = Json.reads[SocialIn]

  override implicit def toPersistence(in: SocialIn): SocialPersistence = SocialConverters.toPersistence(in)

  override implicit def toResponse(in: SocialPersistence): SocialResponse = SocialConverters.toResponse(in)

  override implicit val ResponseMaskable: Maskable[SocialResponse] = new Maskable[SocialResponse] {
    override def applySecureMask(secureMask: SecureMask, accountPattern: String,
                                 output: SocialResponse): SocialResponse = {
      output.copy (
        userId   = SecureMask.idFromEntity(secureMask.entity, accountPattern, output.userId),
        secureId = if (secureMask.overrideSecureIdMask) output.secureId else secureMask.secureId
      )
    }
  }
  override val QP: (Map[String, Seq[String]]) => QueryParameters = QueryParameters.apply
} 
开发者ID:Sharecare,项目名称:health-profile-social-history-play,代码行数:48,代码来源:ServiceController.scala


示例5: coproductWrites

//设置package包名称以及导入依赖的类
package microtools.shapeless

import play.api.data.validation.ValidationError
import play.api.libs.json.{JsError, Json, OWrites, Reads}
import shapeless.{:+:, CNil, Coproduct, Generic, Inl, Inr, Lazy}

trait ShapelessAlgebraicEnum {
  implicit val cNilReads: Reads[CNil] = Reads[CNil](_ => JsError(ValidationError("error.invalid")))

  implicit val cNilWrites: OWrites[CNil] = OWrites[CNil](_ => Json.obj())

  implicit def coproductWrites[H, T <: Coproduct](
      implicit hWrites: Lazy[OWrites[H]],
      tWrites: OWrites[T],
      namingStrategy: NamingStrategy[H]
  ): OWrites[H :+: T] = OWrites[H :+: T] {
    case Inl(h) => hWrites.value.writes(h) ++ namingStrategy.nameFor(h)
    case Inr(t) => tWrites.writes(t)
  }

  implicit def coproductReads[H, T <: Coproduct](
      implicit hReads: Lazy[Reads[H]],
      tReads: Reads[T],
      namingStrategy: NamingStrategy[H]
  ): Reads[H :+: T] = Reads[H :+: T] {
    case json if namingStrategy.verify(json) => hReads.value.reads(json).map(h => Inl(h))
    case json                                => tReads.reads(json).map(t => Inr(t))
  }

  def deriveWrites[T, R](implicit gen: Generic.Aux[T, R], writes: Lazy[OWrites[R]]): OWrites[T] =
    OWrites[T] { obj =>
      writes.value.writes(gen.to(obj))
    }

  def deriveReads[T, R](implicit gen: Generic.Aux[T, R], reads: Lazy[Reads[R]]): Reads[T] =
    reads.value.map(gen.from)

}

object ShapelessAlgebraicEnum extends ShapelessAlgebraicEnum 
开发者ID:21re,项目名称:play-micro-tools,代码行数:41,代码来源:ShapelessAlgebraicEnum.scala


示例6: LightUser

//设置package包名称以及导入依赖的类
package lila.common

import lila.common.PimpedJson._
import play.api.libs.json.{ Json, OWrites }

case class LightUser(
    id: String,
    name: String,
    title: Option[String],
    isPatron: Boolean
) {

  def titleName = title.fold(name)(_ + " " + name)
  def titleNameHtml = title.fold(name)(_ + "&nbsp;" + name)
}

object LightUser {

  implicit val lightUserWrites = OWrites[LightUser] { u =>
    Json.obj(
      "id" -> u.id,
      "name" -> u.name,
      "title" -> u.title,
      "patron" -> u.isPatron
    ).noNull
  }

  type Getter = String => Fu[Option[LightUser]]
  type GetterSync = String => Option[LightUser]
} 
开发者ID:DrNixx,项目名称:line,代码行数:31,代码来源:LightUser.scala


示例7: UserManagerController

//设置package包名称以及导入依赖的类
package controllers

import javax.inject.Singleton

import akka.actor.ActorSystem
import akka.stream.Materializer
import com.google.inject.Inject
import helpers.MongoDB
import models.UserManager
import models.commons.MongoCollectionNames._
import play.api.Configuration
import play.api.libs.json.{OWrites, Reads}
import play.modules.reactivemongo.ReactiveMongoApi
import reactivemongo.play.json.collection.JSONCollection

import scala.concurrent.{ExecutionContext, Future}


@Singleton
class UserManagerController @Inject() (override val reactiveMongoApi: ReactiveMongoApi)
                                      (implicit executionContext: ExecutionContext,
                                       configuration: Configuration,
                                       system: ActorSystem,
                                       materializer: Materializer)
  extends CommonController(reactiveMongoApi) {

  override type P = UserManager
  override implicit val mainCollection: Future[JSONCollection] = getJSONCollection(UserManagers)
  MongoDB.dbs.put(UserManagers,mainCollection)
  override implicit val mainReader: Reads[UserManager] = UserManager.userManagerReader
  override implicit val mainWriter: OWrites[UserManager] = UserManager.userManagerWrites

} 
开发者ID:tictactoki,项目名称:Immutaskable,代码行数:34,代码来源:UserManagerController.scala


示例8: TaskManagerController

//设置package包名称以及导入依赖的类
package controllers

import javax.inject.Singleton

import akka.actor.ActorSystem
import akka.stream.Materializer
import com.google.inject.Inject
import helpers.MongoDB
import models.TaskManager
import models.commons.MongoCollectionNames._
import play.api.Configuration
import play.api.libs.json.{OWrites, Reads}
import play.modules.reactivemongo.ReactiveMongoApi
import reactivemongo.play.json.collection.JSONCollection

import scala.concurrent.{ExecutionContext, Future}


@Singleton
class TaskManagerController @Inject()(override val reactiveMongoApi: ReactiveMongoApi)
                                     (implicit executionContext: ExecutionContext,
                                      configuration: Configuration,
                                      system: ActorSystem,
                                      materializer: Materializer)
  extends CommonController(reactiveMongoApi) {

  override type P = TaskManager
  override implicit val mainCollection: Future[JSONCollection] = getJSONCollection(TaskManagers)
  MongoDB.dbs.put(TaskManagers, mainCollection)
  override implicit val mainReader: Reads[TaskManager] = TaskManager.taskManagerReader
  override implicit val mainWriter: OWrites[TaskManager] = TaskManager.taskManagerWrites

} 
开发者ID:tictactoki,项目名称:Immutaskable,代码行数:34,代码来源:TaskManagerController.scala


示例9: PhilipsScene

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

import play.api.libs.functional.syntax._
import play.api.libs.json.{JsPath, OWrites, Reads}

case class PhilipsScene(
  name: String,
  lights: Seq[String],
  colors: Seq[String],
  default: Boolean)

object PhilipsScene {

  implicit val reads: Reads[PhilipsScene] = (
    (JsPath \ "name").read[String] and
    (JsPath \ "lights").read[Seq[String]] and
    (JsPath \ "colors").read[Seq[String]] and
    (JsPath \ "default").read[Boolean]
  )((name, lights, colors, default) => PhilipsScene.apply(name, lights, colors, default))

  implicit val writes: OWrites[PhilipsScene] = (
    (JsPath \ "name").write[String] and
    (JsPath \ "lights").write[Seq[String]] and
    (JsPath \ "colors").write[Seq[String]] and
    (JsPath \ "default").write[Boolean]
  )(scene => (scene.name.toLowerCase(), scene.lights, scene.colors, scene.default))
} 
开发者ID:acperez,项目名称:DomoControl-Server,代码行数:28,代码来源:PhilipsScene.scala


示例10: VirtualConf

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

import play.api.libs.functional.syntax.unlift
import play.api.libs.functional.syntax._
import play.api.libs.json.{JsPath, OWrites, Reads}
import services.virtual_switch.{VirtualDevice, VirtualService}

case class VirtualConf private(
    id: Int,
    name: String,
    devices: Seq[VirtualDevice]) extends DomoConfiguration(id, name)

object VirtualConf {

  def apply(devices: Seq[VirtualDevice]) =
    new VirtualConf(VirtualService.serviceId, VirtualService.serviceName, devices)

  implicit val reads: Reads[VirtualConf] = (
    (JsPath \ "id").read[Int] and
    (JsPath \ "name").read[String] and
    (JsPath \ "devices").read[Seq[VirtualDevice]]
  )((id, name, devices) => VirtualConf.apply(devices))

  implicit val writes: OWrites[VirtualConf] = (
    (JsPath \ "id").write[Int] and
    (JsPath \ "name").write[String] and
    (JsPath \ "devices").write[Seq[VirtualDevice]]
  )(unlift(VirtualConf.unapply))
} 
开发者ID:acperez,项目名称:DomoControl-Server,代码行数:30,代码来源:VirtualConf.scala


示例11: VirtualDevice

//设置package包名称以及导入依赖的类
package services.virtual_switch

import play.api.libs.functional.syntax._
import play.api.libs.json.{JsPath, OWrites, Reads}

case class VirtualDevice(
    id: String,
    name: String,
    alias: Option[String],
    switches: Seq[SwitchMapping]) {

  def setAlias(value: String): VirtualDevice = copy(alias = Some(value))
}

object VirtualDevice {

  implicit val reads: Reads[VirtualDevice] = (
    (JsPath \ "id").read[String] and
    (JsPath \ "name").read[String] and
    (JsPath \ "alias").readNullable[String] and
    (JsPath \ "switches").read[Seq[SwitchMapping]]
  )(VirtualDevice.apply _)

  implicit val writes: OWrites[VirtualDevice] = (
    (JsPath \ "id").write[String] and
    (JsPath \ "name").write[String] and
    (JsPath \ "alias").writeNullable[String] and
    (JsPath \ "switches").write[Seq[SwitchMapping]]
  )(unlift(VirtualDevice.unapply))
} 
开发者ID:acperez,项目名称:DomoControl-Server,代码行数:31,代码来源:VirtualDevice.scala


示例12: SessionType

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

import play.api.data._
import play.api.data.Forms.{mapping, _}
import play.api.libs.json.{Json, OWrites}

case class SessionType(
  id: Int,
  name: String,
  points: Seq[Int],
  incidentsLimit: Int,
  penaltyPoints: Int
) {}

object SessionType {

  implicit val writes: OWrites[SessionType] = Json.writes[SessionType]

  def getMappingWithMandatoryId() : Mapping[SessionType] = {
    mapping(
      "id" -> number,
      "name" -> nonEmptyText,
      "points" -> seq(number),
      "incidentsLimit" -> number,
      "penaltyPoints" -> number
    )(SessionType.apply)(SessionType.unapply)
  }

  def getMapping() = mapping(
    "id" -> number,
    "name" -> nonEmptyText,
    "points" -> seq(number),
    "incidentsLimit" -> number,
    "penaltyPoints" -> number
  )(SessionType.apply)(SessionType.unapply)

  val form: Form[SessionType] = Form(
    getMapping()
  )
} 
开发者ID:jean-philippe-bousselin,项目名称:orca-api,代码行数:41,代码来源:SessionType.scala


示例13: Session

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

import play.api.data._
import play.api.data.Forms._
import play.api.libs.json.{Json, OWrites}

case class Session(
  id: Int,
  name: String,
  date: String,
  time: String,
  track: Track,
  sessionType: SessionType
) {}

object Session {

  implicit val sessionWrites: OWrites[Session] = Json.writes[Session]

  def getMapping() : Mapping[Session] = mapping(
    "id" -> ignored(0),
    "name" -> text,
    "date" -> text,
    "time" -> text,
    "track" -> Track.getMappingWithMandatoryId(),
    "sessionType" -> SessionType.getMappingWithMandatoryId()
  )(Session.apply)(Session.unapply)

  val form: Form[Session] = Form(getMapping())

} 
开发者ID:jean-philippe-bousselin,项目名称:orca-api,代码行数:32,代码来源:Session.scala


示例14: Championship

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

import play.api.data._
import play.api.data.Forms._
import play.api.libs.json.{Json, OWrites}

case class Championship(
  id: Int = 0,
  name: String,
  description: Option[String],
  thumbnailUrl: Option[String]
) {}

object Championship {

  implicit val configWrites: OWrites[Championship] = Json.writes[Championship]

  val form: Form[Championship] = Form(
    mapping(
      "id" -> ignored(0),
      "name" -> nonEmptyText,
      "description" -> optional(text),
      "thumbnailUrl" -> optional(text)
    )(Championship.apply)(Championship.unapply)
  )

} 
开发者ID:jean-philippe-bousselin,项目名称:orca-api,代码行数:28,代码来源:Championship.scala


示例15: ChampionshipConfiguration

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

import play.api.data._
import play.api.data.Forms._
import play.api.libs.json.{Json, OWrites}

case class ChampionshipConfiguration(
  sessionTypes: Seq[SessionType],
  subClasses: Option[Seq[String]]
) { }

object ChampionshipConfiguration {

  implicit val writes: OWrites[ChampionshipConfiguration] = Json.writes[ChampionshipConfiguration]

  val form: Form[ChampionshipConfiguration] = Form(
    mapping(
      "sessionTypes" -> seq(SessionType.getMapping()),
      "subClasses" -> optional(seq(text))
    )(ChampionshipConfiguration.apply)(ChampionshipConfiguration.unapply)
  )
} 
开发者ID:jean-philippe-bousselin,项目名称:orca-api,代码行数:23,代码来源:ChampionshipConfiguration.scala


示例16: BaseModelDAO

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

import scala.concurrent.Future
import models.DbModel
import models.JsonImpl
import reactivemongo.play.json.collection.JSONCollection
import play.api.libs.json.JsObject
import scala.concurrent.ExecutionContext
import play.api.libs.json.Json
import play.api.libs.json.Reads
import play.api.libs.json.OWrites
import reactivemongo.api.commands.WriteResult
import reactivemongo.play.json.JSONSerializationPack
import play.modules.reactivemongo.json._
import reactivemongo.api.QueryOpts
import models.DbModelComp

abstract class BaseModelDAO[M <: DbModel with JsonImpl](implicit exec: ExecutionContext, implicit val joWrites: OWrites[M],
                                          implicit val joReads: Reads[M]) {

  protected def collection: Future[JSONCollection]

  protected val companionObject: DbModelComp[M]

  final def insert(model: M): Future[WriteResult] = collection.flatMap { collection => collection.insert(model) }

  final def update(model: M): Future[WriteResult] = collection.flatMap(collection => {
    val query = companionObject.queryByUuid(model.uuid)

    collection.update(query, companionObject.getUpdateObject(model))
  })

  final def remove(model: M): Future[Boolean] = collection.flatMap(_.remove(companionObject.queryByUuid(model.uuid)).
    map { wr => wr.ok })

  final def count(query: JsObject): Future[Int] = collection.flatMap(_.count(Some(query)))

  final def findOneByUuid(uuid: String): Future[Option[M]] = find(companionObject.queryByUuid(uuid), 1, 1).map(_.headOption)

  final def find(query: JsObject, page: Int, pageSize: Int): Future[List[M]] =
    collection.flatMap(_.find(query).options(QueryOpts((page - 1) * pageSize, pageSize)).cursor[M]().
      collect[List](pageSize))

  final def findAndSort(query: JsObject, sort: JsObject, page: Int, pageSize: Int): Future[List[M]] =
    collection.flatMap(_.find(query).sort(sort).options(QueryOpts((page - 1) * pageSize, pageSize)).cursor[M]().
      collect[List](pageSize))
} 
开发者ID:MagnusAk78,项目名称:mogas,代码行数:48,代码来源:BaseModelDAO.scala


示例17: LightUser

//设置package包名称以及导入依赖的类
package lila.common

import lila.common.PimpedJson._
import play.api.libs.json.{ Json, OWrites }

case class LightUser(
    id: String,
    name: String,
    title: Option[String],
    isPatron: Boolean
) {

  def titleName = title.fold(name)(_ + " " + name)
  def titleNameHtml = title.fold(name)(_ + "&nbsp;" + name)
}

object LightUser {

  implicit val lightUserWrites = OWrites[LightUser] { u =>
    Json.obj(
      "id" -> u.id,
      "name" -> u.name
    ).add("title" -> u.title)
      .add("patron" -> u.isPatron)
  }

  type Getter = String => Fu[Option[LightUser]]
  type GetterSync = String => Option[LightUser]
} 
开发者ID:Thiediev,项目名称:lilylichessmod,代码行数:30,代码来源:LightUser.scala



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Scala DateTimeParseException类代码示例发布时间:2022-05-23
下一篇:
Scala PublicKey类代码示例发布时间: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