本文整理汇总了Scala中play.api.libs.json.JsPath类的典型用法代码示例。如果您正苦于以下问题:Scala JsPath类的具体用法?Scala JsPath怎么用?Scala JsPath使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JsPath类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: UserReads
//设置package包名称以及导入依赖的类
package it.turingtest.spotify.scala.client.entities
import play.api.libs.json.{JsPath, Reads}
import play.api.libs.functional.syntax._
object UserReads {
val publicUser = {
(JsPath \ "display_name").readNullable[String] and
(JsPath \ "external_urls").read[ExternalURL] and
(JsPath \ "followers").readNullable[Followers] and
(JsPath \ "href").read[String] and
(JsPath \ "id").read[String] and
((JsPath \ "images").read[Seq[Image]] or Reads.pure(Seq.empty[Image])) and
(JsPath \ "type").read[String] and
(JsPath \ "uri").read[String]
}
val privateUser = {
publicUser and
(JsPath \ "birthdate").readNullable[String] and
(JsPath \ "country").readNullable[String] and
(JsPath \ "email").readNullable[String] and
(JsPath \ "product").readNullable[String]
}
}
case class UserPrivate
(
display_name: Option[String],
external_urls: ExternalURL,
followers: Option[Followers],
href: String,
id: String,
images: Seq[Image],
objectType: String,
uri: String,
birthdate: Option[String],
country: Option[String],
email: Option[String],
product: Option[String]
)
object UserPrivate {
implicit val userPrivateReads: Reads[UserPrivate] = UserReads.privateUser(UserPrivate.apply _)
}
开发者ID:bartholomews,项目名称:spotify-scala-client,代码行数:49,代码来源:User.scala
示例2: asThrowable
//设置package包名称以及导入依赖的类
package ca.schwitzer.scaladon
import akka.http.scaladsl.model.StatusCode
import play.api.libs.json.{JsPath, JsonValidationError}
sealed trait MastodonResponse[+A]
sealed trait MastodonError extends MastodonResponse[Nothing] {
def asThrowable: Throwable
}
object MastodonResponses {
case class Success[+A](elem: A) extends MastodonResponse[A]
}
object MastodonErrors {
case class JSONParseError(e: Throwable) extends MastodonError {
def asThrowable: Throwable = new Exception(toString)
override def toString: String = s"$e"
}
case class JSONValidationError(jsErrors: Seq[(JsPath, Seq[JsonValidationError])], e: Throwable) extends MastodonError {
def asThrowable: Throwable = new Exception(toString)
override def toString: String = s"$e\n$jsErrors"
}
case class ResponseError(statusCode: StatusCode, e: Throwable) extends MastodonError {
def asThrowable: Throwable = new Exception(toString)
override def toString: String = s"$statusCode\n$e"
}
}
开发者ID:schwitzerm,项目名称:scaladon,代码行数:34,代码来源:MastodonResponse.scala
示例3: WSGitHubAuthor
//设置package包名称以及导入依赖的类
package models
import play.api.libs.functional.syntax._
import play.api.libs.json.{JsPath, Json, Reads, Writes}
case class WSGitHubAuthor(login: String, avatarUrl: String)
object WSGitHubAuthor {
implicit val gitHubAuthorReads: Reads[WSGitHubAuthor] = (
(JsPath \ "login").read[String] and
(JsPath \ "avatar_url").read[String]
)(WSGitHubAuthor.apply _)
implicit val gitHubAuthorWriters = new Writes[WSGitHubAuthor] {
def writes(gitHubAuthor: WSGitHubAuthor) = Json.obj(
"login" -> gitHubAuthor.login,
"avatar_url" -> gitHubAuthor.avatarUrl
)
}
}
case class WSGitHubContributor(totalCommits: Int, author: WSGitHubAuthor)
object WSGitHubContributor {
implicit val gitHubContributorReads: Reads[WSGitHubContributor] = (
(JsPath \ "total").read[Int] and
(JsPath \ "author").read[WSGitHubAuthor]
)(WSGitHubContributor.apply _)
implicit val gitHubContributorWriters = new Writes[WSGitHubContributor] {
def writes(gitHubContributor: WSGitHubContributor) = Json.obj(
"totalCommits" -> gitHubContributor.totalCommits,
"author" -> gitHubContributor.author
)
}
}
开发者ID:helde,项目名称:GitHubRepositoriesActivities,代码行数:37,代码来源:WSGitHubContributor.scala
示例4: WSGitHubCommit
//设置package包名称以及导入依赖的类
package models
import java.text.SimpleDateFormat
import java.util.Date
import play.api.libs.functional.syntax._
import play.api.libs.json.{JsPath, Json, Reads, Writes}
case class WSGitHubCommit(committer: String, date: Date) {
def getFormatedDate: String = {
val dateFormat: SimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd")
dateFormat.format(date)
}
}
object WSGitHubCommit {
implicit val gitHubProjectSummaryReads: Reads[WSGitHubCommit] = (
(JsPath \ "email").read[String] and
(JsPath \ "date").read[Date]
)(WSGitHubCommit.apply _)
implicit val gitHubProjectSummaryWriters = new Writes[WSGitHubCommit] {
def writes(gitHubProjectSummary: WSGitHubCommit) = Json.obj(
"email" -> gitHubProjectSummary.committer,
"date" -> gitHubProjectSummary.date
)
}
}
开发者ID:helde,项目名称:GitHubRepositoriesActivities,代码行数:29,代码来源:WSGitHubCommit.scala
示例5: node
//设置package包名称以及导入依赖的类
package models
import play.api.libs.json.{JsPath, Writes}
import play.api.libs.functional.syntax._
trait FsElement {
def node: FsNode
}
object FsElement {
implicit val fsElementWrites: Writes[FsElement] = (
(JsPath \ "id").write[String] and
(JsPath \ "location").write[String] and
(JsPath \ "name").write[String] and
(JsPath \ "type").write[String] and
(JsPath \ "creation").write[String] and
(JsPath \ "modification").write[String] and
(JsPath \ "hidden").write[Boolean] and
//(JsPath \ "creator").write[Account] and
(JsPath \ "content").lazyWriteNullable(Writes.seq[FsElement](fsElementWrites)) and
(JsPath \ "sources").lazyWriteNullable(Writes.seq[FileSource](FileSource.fileSourceWrites))
)(element => (
element.node.id.toString,
element.node.location.toString,
element.node.name,
element.node.nodeType,
element.node.creation.toString,
element.node.modification.toString,
element.node.hidden,
//element.node.creator
element match {
case dir: Directory if dir.content.nonEmpty => Some(dir.content)
case _ => None
},
element match {
case file: File => Some(file.sources)
case _ => None
})
)
}
开发者ID:Cumulus-Cloud,项目名称:cumulus,代码行数:43,代码来源:FsElement.scala
示例6: FileSource
//设置package包名称以及导入依赖的类
package models
import java.util.UUID
import org.joda.time.DateTime
import play.api.libs.functional.syntax._
import play.api.libs.json.{JsPath, Writes}
import storage.FileStorageEngine
case class FileSource(
id: UUID,
size: BigInt,
hash: String,
cipher: Option[String],
compression: Option[String],
key: Option[String],
storageEngine: String,
storageEngineVersion: String,
creation: DateTime
)
object FileSource {
def initFrom(engine: FileStorageEngine): FileSource = FileSource(
UUID.randomUUID(),
0,
"d41d8cd98f00b204e9800998ecf8427e", // MD5 of an empty string/file
None,
None,
None,
engine.name,
engine.version,
DateTime.now()
)
implicit val fileSourceWrites: Writes[FileSource] = (
(JsPath \ "id").write[String] and
(JsPath \ "size").write[Int] and
(JsPath \ "hash").write[String] and
(JsPath \ "cipher").write[String] and
(JsPath \ "compression").write[String] and
(JsPath \ "storageEngine").write[String] and
(JsPath \ "storageEngineVersion").write[String] and
(JsPath \ "creation").write[DateTime]
)(source => (
source.id.toString,
source.size.toInt,
source.hash,
source.cipher.getOrElse("none"),
source.compression.getOrElse("none"),
source.storageEngine,
source.storageEngineVersion,
source.creation)
)
}
开发者ID:Cumulus-Cloud,项目名称:cumulus,代码行数:57,代码来源:File.scala
示例7: DockerEnvironment
//设置package包名称以及导入依赖的类
package codacy.dockerApi
import java.nio.file.{Files, Paths}
import codacy.dockerApi.api.CodacyConfiguration
import play.api.data.validation.ValidationError
import play.api.libs.json.{JsError, JsPath, Json}
import scala.util.{Failure, Success, Try}
object DockerEnvironment {
def config: Try[CodacyConfiguration] = Try(Files.readAllBytes(configFilePath)).transform(
raw => Try(Json.parse(raw)).flatMap(
_.validate[CodacyConfiguration].fold(
asFailure,
conf => Success(conf)
)),
error => Failure(error)
)
private[this] def asFailure(error: Seq[(JsPath, Seq[ValidationError])]) =
Failure(new Throwable(Json.stringify(JsError.toFlatJson(error.toList))))
private[this] lazy val configFilePath = sourcePath.resolve(".codacyrc")
lazy val sourcePath = Paths.get("/src")
}
开发者ID:codacy,项目名称:codacy-duplication-scala-seed,代码行数:29,代码来源:DockerEnvironment.scala
示例8: UserController
//设置package包名称以及导入依赖的类
package controllers.user
import models.user.User
import play.api.libs.functional.syntax._
import play.api.libs.json.{JsPath, Json, Writes}
import play.api.mvc._
class UserController extends Controller{
def list = Action { implicit request =>
val users = User.fetchAll()
Ok(Json.toJson(users))
}
implicit val locationWrites: Writes[User] = (
(JsPath \ "id").write[Int] and
(JsPath \ "username").write[String] and
(JsPath \ "password").write[String]
) (unlift(User.unapply))
}
开发者ID:beisser,项目名称:play2SkeletonApplication,代码行数:21,代码来源:UserController.scala
示例9: Deployment
//设置package包名称以及导入依赖的类
package models
import play.api.libs.functional.syntax._
import play.api.libs.json.{JsPath, Json, Reads}
case class Deployment(amiId: String, version: String)
object Deployment {
implicit val reads: Reads[Deployment] = (
(JsPath \ "ami_id").read[String] and
(JsPath \ "version").read[String]
)(Deployment.apply _)
implicit val writes = Json.writes[Deployment]
}
case class DeleteStack(version: String)
object DeleteStack {
implicit val reads: Reads[DeleteStack] = (JsPath \ "version").read[String].map(DeleteStack(_))
implicit val writes = Json.writes[DeleteStack]
}
开发者ID:lifeway,项目名称:Chadash,代码行数:22,代码来源:Deployment.scala
示例10: jsonException
//设置package包名称以及导入依赖的类
package org.birdfeed.chirp.errors
import play.api.data.validation.ValidationError
import play.api.libs.json.{JsError, JsPath, JsValue, Json}
trait JsonError {
def jsonException(message: String, exception: Exception = new Exception): JsValue = {
Json.obj(
"error" -> message,
"details" -> Json.obj(
"exception_class" -> exception.getClass.toString,
"message" -> exception.toString
)
)
}
def jsonError(message: String): JsValue = Json.obj(
"error" -> message
)
def jsonValidationError(message: String, errors: Seq[(JsPath, Seq[ValidationError])]): JsValue = {
Json.obj("error" -> message, "details" -> JsError.toJson(errors))
}
}
开发者ID:AwesomeIT,项目名称:chirp,代码行数:25,代码来源:JsonError.scala
示例11: writes
//设置package包名称以及导入依赖的类
package helpers
import models.Person
import org.joda.time.DateTime
import org.scalatestplus.play.{ OneAppPerTest, PlaySpec }
import play.api.libs.functional.syntax._
import play.api.libs.json.{ JsPath, Json, Reads, Writes }
import play.api.mvc.Result
import play.api.test.Helpers._
import play.api.test.{ FakeHeaders, FakeRequest }
import scala.concurrent.Future
trait PersonTestHelper extends PlaySpec with OneAppPerTest {
private val PostHeaders = FakeHeaders(Seq("Content-type" -> "application/json"))
private implicit val PersonWrites = new Writes[Person] {
def writes(person: Person) = Json.obj(
"id" -> person.id,
"name" -> person.name,
"age" -> person.age,
"lastUpdate" -> person.lastUpdate
)
}
private implicit val PersonReads: Reads[Person] = (
(JsPath \ "id").read[Long] and
(JsPath \ "name").read[String] and
(JsPath \ "age").read[Int] and
(JsPath \ "lastUpdate").read[DateTime]
)(Person.apply _)
def getPeople: Future[Result] = {
val postRequest = FakeRequest(GET, controllers.routes.PersonController.returnPeople().url)
route(app, postRequest).get
}
def postPerson(person: Person): Future[Result] = {
val json = Json.toJson(person)
val request = FakeRequest(POST, controllers.routes.PersonController.createPerson().url, PostHeaders, json)
route(app, request).get
}
def persons(response: Future[Result]): Seq[Person] = {
Json.fromJson[Seq[Person]](Json.parse(contentAsString(response))).get
}
}
开发者ID:marciogualtieri,项目名称:PersonService,代码行数:49,代码来源:PersonTestHelper.scala
示例12: createToken
//设置package包名称以及导入依赖的类
package im.actor.server.oauth
import akka.http.scaladsl.unmarshalling.PredefinedFromEntityUnmarshallers._
import akka.http.scaladsl.unmarshalling._
import akka.stream.Materializer
import play.api.libs.functional.syntax._
import play.api.libs.json.{ JsPath, Json, Reads }
trait Implicits {
implicit val materializer: Materializer
implicit val tokenReads: Reads[Token] =
((JsPath \ "access_token").read[String] and
(JsPath \ "token_type").read[String] and
(JsPath \ "expires_in").read[Long] and
(JsPath \ "refresh_token").readNullable[String])(createToken _)
implicit val profileReads: Reads[Profile] =
((JsPath \ "email").read[String] and
(JsPath \ "family_name").readNullable[String] and
(JsPath \ "name").readNullable[String] and
(JsPath \ "given_name").readNullable[String] and
(JsPath \ "picture").readNullable[String] and
(JsPath \ "gender").readNullable[String] and
(JsPath \ "locale").readNullable[String])(Profile)
private def createToken(accessToken: String, tokenType: String, expiresIn: Long, refreshToken: Option[String]) =
Token(accessToken, tokenType, expiresIn, refreshToken)
implicit val toOAuthToken: FromResponseUnmarshaller[Option[Token]] = Unmarshaller { implicit ec ? resp ?
Unmarshal(resp.entity).to[String].map { body ?
Json.parse(body).validate[Token].fold(errors ? None, token ? Some(token))
}
}
implicit val toProfile: FromResponseUnmarshaller[Option[Profile]] = Unmarshaller { implicit ec ? resp ?
Unmarshal(resp.entity).to[String].map { body ?
Json.parse(body).validate[Profile].fold(errors ? None, profile ? Some(profile))
}
}
}
开发者ID:wex5,项目名称:dangchat-server,代码行数:43,代码来源:Implicits.scala
示例13: WavesPayment
//设置package包名称以及导入依赖的类
package models
import play.api.libs.functional.syntax._
import play.api.libs.json.{JsPath, Writes}
/**
*
*/
case class WavesPayment(sender: String, recipient: String, amount: Long, fee: Long)
object WavesPayment {
implicit val wavesPaymentWrites : Writes[WavesPayment] = (
(JsPath \ "sender").write[String] and
(JsPath \ "recipient").write[String] and
(JsPath \ "amount").write[Long] and
(JsPath \ "fee").write[Long]
)(unlift(WavesPayment.unapply))
}
开发者ID:gagarin55,项目名称:WavesFaucet,代码行数:21,代码来源:WavesPayment.scala
示例14: Validation
//设置package包名称以及导入依赖的类
package utils
import play.api.Play.current
import play.api.data.validation.ValidationError
import play.api.i18n.Messages
import play.api.i18n.Messages.Implicits._
import play.api.libs.json.Json._
import play.api.libs.json.{JsObject, JsPath, Json}
import play.api.mvc._
import scala.concurrent.Future
object Validation extends Controller {
def validationError(code: Int)(errors: Seq[(JsPath, Seq[ValidationError])]): Future[Result] = {
def messageFormat: JsObject = {
errors.foldLeft(Json.obj()) { (obj, error) =>
obj ++ Json.obj(error._1.toString().replaceFirst(Constants.Global.SLASH, Constants.Global.EMPTY_STRING) -> error._2.foldLeft(Json.arr()) { (arr, err) =>
arr :+ Json.obj(Constants.Global.MESSAGE -> Messages(err.message, if (err.args.nonEmpty) err.args.head).toString)
})
}
}
Future.successful(BadRequest(obj(Constants.Global.STATUS -> code, Constants.Global.ERROR_MESSAGE -> messageFormat)))
}
}
开发者ID:satriapribadi,项目名称:satriapribadi.com,代码行数:27,代码来源:Validation.scala
示例15: 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
示例16: Eidolon
//设置package包名称以及导入依赖的类
package modules
import play.api.libs.functional.syntax
import play.api.libs.json.{JsPath, Writes}
object Eidolon {
import play.api.libs.functional.syntax._
implicit val eidolonWrites: Writes[Eidolon] = (
(JsPath \ "lastDate").write[String] and
(JsPath \ "regressionPrediction").write[RegressionPrediction] and
(JsPath \ "classifierPrediction").write[ClassifierPrediction]
) (syntax.unlift(Eidolon.unapply))
}
case class Eidolon(d: String, r: RegressionPrediction, c: ClassifierPrediction) {
val lastDate = d
val regressionPrediction = r
val classifierPrediction = c
override def toString: String = "{lastDate:" + lastDate + ", " +
"regressionPrediction: {RMSE : " + regressionPrediction.rmse + ", value: " + regressionPrediction.result + "}," +
"classCastException: {accuracy:" + classifierPrediction.accuracy + ", change:" + classifierPrediction.result + " }}"
}
开发者ID:xiren,项目名称:Apollo,代码行数:27,代码来源:Eidiolon.scala
示例17: RegressionPrediction
//设置package包名称以及导入依赖的类
package modules
import play.api.libs.functional.syntax._
import play.api.libs.json.{JsPath, Writes}
object RegressionPrediction {
implicit val regressionPredictionWrites: Writes[RegressionPrediction] = (
(JsPath \ "rmse").write[Double] and
(JsPath \ "chain").write[Double] and
(JsPath \ "result").write[Double]
) (unlift(RegressionPrediction.unapply))
}
case class RegressionPrediction(a: Double, c: Double, r: Double) {
val rmse = a
val chain = c
val result = r
}
开发者ID:xiren,项目名称:Apollo,代码行数:21,代码来源:RegressionPrediction.scala
示例18: GitHubVerifierActor
//设置package包名称以及导入依赖的类
package com.pedrorijo91.status.actor
import com.pedrorijo91.status.Config
import com.pedrorijo91.status.model.GitHubStatus
import com.pedrorijo91.status.notifier.NotificationCenter
import play.api.data.validation.ValidationError
import play.api.libs.json.JsPath
import play.api.libs.ws.WSResponse
import scala.concurrent.ExecutionContext.Implicits.global
class GitHubVerifierActor extends StatusActor[GitHubStatus] {
private val actorMessage = "github"
val tick = context.system.scheduler.schedule(Config.initialDelay, Config.checkInterval, self, actorMessage)
// docs: https://status.github.com/api
private val githubURL = "https://status.github.com/api/status.json"
def receive = {
case `actorMessage` =>
check(githubURL)
}
protected def validate(response: WSResponse): Either[Seq[(JsPath, Seq[ValidationError])], GitHubStatus] = {
response.json.validate[GitHubStatus].asEither
}
protected def hasChanged(prev: GitHubStatus, current: GitHubStatus): Boolean = {
prev.lastUpdated != current.lastUpdated && prev.status != current.status
}
protected def onChange(prev: GitHubStatus, current: GitHubStatus): Unit = {
NotificationCenter.sendNotification(prev, current)
}
}
开发者ID:pedrorijo91,项目名称:git-status-notifier,代码行数:37,代码来源:GitHubVerifierActor.scala
示例19: BitbucketVerifierActor
//设置package包名称以及导入依赖的类
package com.pedrorijo91.status.actor
import com.pedrorijo91.status.Config
import com.pedrorijo91.status.model.BitbucketStatus
import com.pedrorijo91.status.notifier.NotificationCenter
import play.api.data.validation.ValidationError
import play.api.libs.json.JsPath
import play.api.libs.ws.WSResponse
import scala.concurrent.ExecutionContext.Implicits.global
class BitbucketVerifierActor extends StatusActor[BitbucketStatus] {
private val actorMessage = "bitbucket"
val tick = context.system.scheduler.schedule(Config.initialDelay, Config.checkInterval, self, actorMessage)
// docs: http://status.bitbucket.org/api
private val bitbucketUrl = "http://bqlf8qjztdtr.statuspage.io/api/v2/status.json"
def receive = {
case `actorMessage` =>
check(bitbucketUrl)
}
protected def validate(response: WSResponse): Either[Seq[(JsPath, Seq[ValidationError])], BitbucketStatus] = {
response.json.validate[BitbucketStatus].asEither
}
protected def hasChanged(prev: BitbucketStatus, current: BitbucketStatus): Boolean = {
prev.updatedAt != current.updatedAt && prev.status != current.status
}
protected def onChange(prev: BitbucketStatus, current: BitbucketStatus): Unit = {
NotificationCenter.sendNotification(prev, current)
}
}
开发者ID:pedrorijo91,项目名称:git-status-notifier,代码行数:37,代码来源:BitbucketVerifierActor.scala
示例20: UserActivityQuery
//设置package包名称以及导入依赖的类
package io.soheila.um.vos.activities
import java.time.LocalDateTime
import io.soheila.um.types.ActivityType.ActivityType
import play.api.libs.functional.syntax._
import play.api.libs.json.{ JsPath, Writes }
case class UserActivityQuery(
earlierThan: Option[LocalDateTime] = None,
laterThan: Option[LocalDateTime] = None,
activityType: Option[ActivityType] = None,
userUUID: Option[String] = None,
sortFilter: Option[(String, Int)] = None
)
object UserActivityQuery {
implicit val residentWrites: Writes[UserActivityQuery] = (
(JsPath \ "timestamp" \ "$lte").writeNullable[LocalDateTime] and
(JsPath \ "timestamp" \ "$gte").writeNullable[LocalDateTime] and
(JsPath \ "activityType").writeNullable[ActivityType] and
(JsPath \ "userUUID").writeNullable[String]
)(ucq => (ucq.earlierThan, ucq.laterThan, ucq.activityType, ucq.userUUID))
}
开发者ID:esfand-r,项目名称:soheila-um,代码行数:25,代码来源:UserActivityQuery.scala
注:本文中的play.api.libs.json.JsPath类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论