本文整理汇总了Scala中play.api.libs.json.JsBoolean类的典型用法代码示例。如果您正苦于以下问题:Scala JsBoolean类的具体用法?Scala JsBoolean怎么用?Scala JsBoolean使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JsBoolean类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: TestController
//设置package包名称以及导入依赖的类
package uk.gov.bis.levyApiMock.controllers.security
import play.api.libs.json.{JsBoolean, JsObject, JsString}
import play.api.mvc.{Action, Controller}
import uk.gov.bis.levyApiMock.auth.TOTP
class TestController extends Controller {
def generateToken(secret: String, ts: Option[Long]) = Action {
val token = TOTP.generateCodeAtTime(secret, ts.getOrElse(System.currentTimeMillis())).value
Ok(JsObject(Seq("token" -> JsString(token))))
}
def checkToken(secret: String, token: String, ts: Option[Long]) = Action {
val generatedToken = TOTP.generateCodeAtTime(secret, ts.getOrElse(System.currentTimeMillis())).value
val valid = generatedToken == token
Ok(JsObject(Seq("valid" -> JsBoolean(valid))))
}
}
开发者ID:UKGovernmentBEIS,项目名称:das-alpha-hmrc-api-mock,代码行数:22,代码来源:TestController.scala
示例2: ShapelessCoproductJsonSpec
//设置package包名称以及导入依赖的类
package microtools.shapeless
import org.scalatest.MustMatchers
import org.scalatestplus.play.PlaySpec
import play.api.libs.json.{JsBoolean, JsNumber, JsString, Json}
import shapeless._
class ShapelessCoproductJsonSpec extends PlaySpec with MustMatchers {
import ShapelessCoproductJson._
"Shapeless writes" should {
"serialize a simple coproduct" in {
type ISB = Int :+: String :+: Boolean :+: CNil
val isb1 = Coproduct[ISB](1234)
val isb2 = Coproduct[ISB]("string")
val isb3 = Coproduct[ISB](true)
Json.toJson(isb1) mustBe JsNumber(1234)
Json.toJson(isb2) mustBe JsString("string")
Json.toJson(isb3) mustBe JsBoolean(true)
}
}
"Shapeless reads" should {
"deserialize a simple coproduct" in {
type ISB = Int :+: String :+: Boolean :+: CNil
val isb1 = JsBoolean(true).as[ISB]
val isb2 = JsString("string").as[ISB]
val isb3 = JsNumber(1234).as[ISB]
isb1.select[Boolean] mustBe Some(true)
isb2.select[String] mustBe Some("string")
isb3.select[Int] mustBe Some(1234)
}
}
}
开发者ID:21re,项目名称:play-micro-tools,代码行数:39,代码来源:ShapelessCoproductJsonSpec.scala
示例3: SubscriptionController
//设置package包名称以及导入依赖的类
package com.clemble.loveit.user.controller
import javax.inject.{Inject, Singleton}
import com.clemble.loveit.user.service.SubscriptionManager
import play.api.libs.json.{JsBoolean, JsDefined, JsObject, JsString}
import play.api.mvc.{Action, Controller}
import scala.concurrent.{ExecutionContext, Future}
@Singleton
class SubscriptionController @Inject() (subManager: SubscriptionManager, implicit val ec: ExecutionContext) extends Controller {
def subscribeCreator() = Action.async(parse.json[JsObject].map(_ \ "email"))(implicit req => {
req.body match {
case JsDefined(JsString(email)) =>
subManager.
subscribeCreator(email).
map(res => Ok(JsBoolean(res)))
case _ =>
Future.successful(NotFound)
}
})
def subscribeContributor() = Action.async(parse.json[JsObject].map(_ \ "email"))(implicit req => {
req.body match {
case JsDefined(JsString(email)) =>
subManager.
subscribeContributor(email).
map(res => Ok(JsBoolean(res)))
case _ =>
Future.successful(NotFound)
}
})
}
开发者ID:thankyo,项目名称:thank,代码行数:37,代码来源:SubscriptionController.scala
示例4: ctx
//设置package包名称以及导入依赖的类
package biz.interop
import play.api.libs.json.{JsBoolean, JsObject, JsString, Json}
import play.modules.reactivemongo.json.collection.JSONCollection
import reactivemongo.api.DB
import scala.concurrent.{ExecutionContext, Future}
trait CanConnectDB {
def ctx(db: DB): JSONCollection
val defaultIdentityField = "_id"
def identityQuery(value: String, identityField: String = defaultIdentityField): JsObject =
Json.obj(identityField -> JsString(value))
def fieldsProjection(fields: String*): JsObject = {
val project = fields.filter(! _.trim.isEmpty).map(_ -> JsBoolean(true))
JsObject(project)
}
val allQuery = Json.obj()
def count
(db: DB, value: String, identityField: String = defaultIdentityField)
(implicit ec: ExecutionContext): Future[Int] = {
ctx(db).count(Some(identityQuery(value, identityField)))
}
def any
(db: DB, value: String, identityField: String = defaultIdentityField)
(implicit ec: ExecutionContext): Future[Boolean] = {
count(db, value, identityField).map(_ > 0)
}
}
开发者ID:scozv,项目名称:bolero,代码行数:33,代码来源:CanConnectDB.scala
注:本文中的play.api.libs.json.JsBoolean类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论