本文整理汇总了Scala中spray.httpx.SprayJsonSupport类的典型用法代码示例。如果您正苦于以下问题:Scala SprayJsonSupport类的具体用法?Scala SprayJsonSupport怎么用?Scala SprayJsonSupport使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SprayJsonSupport类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: submitOrder
//设置package包名称以及导入依赖的类
package com.github.eventdrivenorders.api
import com.github.eventdrivenorders.api.dto.NewOrderRequest
import com.github.eventdrivenorders.api.json.OrderFormats._
import domain.Order
import spray.httpx.SprayJsonSupport
import spray.json._
import spray.routing.HttpService
trait ApiRoutes extends HttpService with SprayJsonSupport {
def submitOrder(order: Order): Unit
def getStatus(orderId: Long): Option[String]
val routes = path("orders") {
post {
entity(as[NewOrderRequest]) { order =>
complete {
val orderId = OrderIDGenerator.next
println(s"New order request: $orderId $order")
submitOrder(Order(orderId, order.products))
JsObject(("orderId", JsNumber(orderId)))
}
}
}
} ~ path("orders" / LongNumber) { orderId =>
get {
complete {
getStatus(orderId).map { status =>
JsObject(("orderId", JsNumber(orderId)), ("status", JsString(status)))
}
}
}
}
}
开发者ID:simonko91,项目名称:event-driven-orders,代码行数:41,代码来源:ApiRoutes.scala
示例2: CreditApprovalsServiceActor
//设置package包名称以及导入依赖的类
package org.kda.credit.service
import akka.actor.Actor
import spray.httpx.SprayJsonSupport
import spray.routing.{HttpService, Route}
import org.kda.credit.model._
import spray.httpx.SprayJsonSupport._
class CreditApprovalsServiceActor extends Actor with CreditApprovalsService {
def actorRefFactory = {
context
}
def receive = {
runRoute( applicationRoute )
}
}
trait CreditApprovalsService extends HttpService with SprayJsonSupport {
import spray.http.MediaTypes._
import org.kda.credit.model.{ApprovedApplication, PendingApplication, CreditLine, Customer}
import org.kda.credit.service.CreditApprovalJSonProtocol._
//@formatter:off
val applicationRoute: Route =
path( "credit-approvals" ) {
get {
complete {
PendingApplication( "123" ) // you can POST this payload to the service to convert it into an approved application
}
} ~
post {
respondWithMediaType( `application/json` )
entity( as[ PendingApplication ] ) { application =>
detach() {
// in Part 4 this code will be integrated with the rules engine to actually perform the business logic
val customer = Customer( application.customerId, 400 )
val credit = CreditLine( customer, BigDecimal( 5000 ) )
complete {
ApprovedApplication( customer.id, Some( credit ) )
}
}
}
}
}
}
开发者ID:knowledgedataaction,项目名称:credit-approvals,代码行数:48,代码来源:CreditService.scala
示例3: RouterActor
//设置package包名称以及导入依赖的类
package com.example.routing
import akka.actor.{Actor, ActorLogging, Props}
import com.example.actors.TimetableActor
import com.example.ticketHub.TimetableQueryMessage
import spray.httpx.SprayJsonSupport
import spray.routing.HttpService
class RouterActor extends HttpService with Actor with ActorLogging with SprayJsonSupport{
implicit def actorRefFactory = context
def timetableActor = context.actorOf(Props[TimetableActor])
def receive = runRoute(route)
val route = {
get{
pathPrefix("akka"){
pathEndOrSingleSlash{
getFromResource("web/html/index.html")
}
} ~
path("akka" / "health") {
complete {
"ticket hub alive"
}
} ~
path("akka" / "timetable") {
parameter('trainRef.as[Int]){ trainRef =>
ctx => timetableActor ! TimetableQueryMessage(ctx,trainRef)
}
}
}
}
}
开发者ID:ChengGit,项目名称:ticketHub,代码行数:37,代码来源:RouterActor.scala
示例4: InputTextMessageContent
//设置package包名称以及导入依赖的类
package io.rockneurotiko.scalagram.types
import spray.httpx.SprayJsonSupport
import spray.json._
sealed trait InputMessageContent
case class InputTextMessageContent(
messageText: String,
parseMode: Option[String] = None,
disableWebPagePreview: Option[Boolean] = None
) extends InputMessageContent
case class InputLocationMessageContent(
latitude: Double,
longitude: Double
) extends InputMessageContent
case class InputVenueMessageContent(
latitude: Double,
longitude: Double,
title : String,
address: String,
foursquareId: Option[String] = None
) extends InputMessageContent
case class InputContactMessageContent(
phoneNumber: String,
firstName: String,
lastName: Option[String] = None
) extends InputMessageContent
object InputMessageContentSupport extends DefaultJsonProtocol with SprayJsonSupport {
implicit val inputTextMessageContentFormat = jsonFormat(InputTextMessageContent, "message_text", "parse_mode", "disable_web_page_preview")
implicit val inputLocationMessageContentFormat = jsonFormat(InputLocationMessageContent, "latitude", "longitude")
implicit val inputVenueMessageContentFormat = jsonFormat(InputVenueMessageContent, "latitude", "longitude", "title", "address", "foursquareId")
implicit val inputContactMessageContentFormat = jsonFormat(InputContactMessageContent, "phoneNumber", "firstName", "lastName")
implicit object inputMessageContentFormat extends RootJsonFormat[InputMessageContent] {
def write(im: InputMessageContent) = im match {
case m: InputTextMessageContent => m.toJson
case r: InputLocationMessageContent => r.toJson
case v: InputVenueMessageContent => v.toJson
case c: InputContactMessageContent => c.toJson
}
def read(v: JsValue) = InputTextMessageContent("")
}
}
开发者ID:rockneurotiko,项目名称:scalagram,代码行数:50,代码来源:InputMessageContent.scala
示例5: ChatMemberTypes
//设置package包名称以及导入依赖的类
package io.rockneurotiko.scalagram.types
import spray.httpx.SprayJsonSupport
import spray.json._
object ChatMemberTypes extends DefaultJsonProtocol with SprayJsonSupport {
sealed trait ChatMemberStatus
case object Creator extends ChatMemberStatus
case object Administrator extends ChatMemberStatus
case object Member extends ChatMemberStatus
case object MemberLeft extends ChatMemberStatus
case object MemberKicked extends ChatMemberStatus
implicit def chatMemberTypeToStr(q: String): ChatMemberStatus = q match {
case "creator" => Creator
case "administrator" => Administrator
case "member" => Member
case "left" => MemberLeft
case "kicked" => MemberKicked
case _ => Member
}
implicit object chatmemberTypeFormat extends JsonFormat[ChatMemberStatus] {
def write(i: ChatMemberStatus) = JsString("")
def read(v: JsValue) = {
val JsString(s) = v
s
}
}
import io.rockneurotiko.scalagram.types.TypesJsonSupport._
implicit def chatMemberFormat = jsonFormat(ChatMember, "user", "status")
}
import ChatMemberTypes._
case class ChatMember(
user: User,
status: ChatMemberStatus)
开发者ID:rockneurotiko,项目名称:scalagram,代码行数:40,代码来源:ChatMember.scala
示例6: KeyboardButton
//设置package包名称以及导入依赖的类
package io.rockneurotiko.scalagram.types
import spray.httpx.SprayJsonSupport
import spray.json._
case class KeyboardButton(
text: String,
requestContact: Option[Boolean] = None,
requestLocation: Option[Boolean] = None)
sealed trait ReplyMarkup
case class ReplyKeyboardMarkup(
keyboard: Seq[Seq[KeyboardButton]],
resizeKeyboard: Option[Boolean] = None,
oneTimeKeyboard: Option[Boolean] = None,
selective: Option[Boolean] = None) extends ReplyMarkup
case class ReplyKeyboardHide(
hideKeyboard: Boolean,
selective: Option[Boolean] = None) extends ReplyMarkup
case class ForceReply(
forceReply: Boolean,
selective: Option[Boolean] = None) extends ReplyMarkup
case class InlineKeyboardMarkup(
inlineKeyboard: Seq[Seq[InlineKeyboardButton]]) extends ReplyMarkup
case class InlineKeyboardButton(
text: String,
url: Option[String] = None,
callbackData: Option[String] = None,
switchInlineQuery: Option[String] = None)
object ReplyMarkupSupport extends DefaultJsonProtocol with SprayJsonSupport {
implicit val keyboardButtonFormat = jsonFormat(KeyboardButton, "text", "request_contact", "request_location")
implicit val replyKeyboardMarkupFormat = jsonFormat(ReplyKeyboardMarkup, "keyboard", "resize_keyboard", "one_time_keyboard", "selective")
implicit val replyKeyboardHideFormat = jsonFormat(ReplyKeyboardHide, "hide_keyboard", "selective")
implicit val forceReplyFormat = jsonFormat(ForceReply, "force_reply", "selective")
implicit val inlineKeyboardButtonFormat = jsonFormat(InlineKeyboardButton, "text", "url", "callback_data", "switch_inline_query")
implicit val inlineKeyboardMarkupFormat = jsonFormat(InlineKeyboardMarkup, "inline_keyboard")
implicit object replyMarkupFormat extends RootJsonFormat[ReplyMarkup] {
def write(r: ReplyMarkup) = r match {
case rk: ReplyKeyboardMarkup => rk.toJson
case fr: ForceReply => fr.toJson
case rk: ReplyKeyboardHide => rk.toJson
case ik: InlineKeyboardMarkup => ik.toJson
}
def read(v: JsValue) = ForceReply(true)
}
}
开发者ID:rockneurotiko,项目名称:scalagram,代码行数:55,代码来源:ReplyMarkup.scala
示例7: getOptionStringField
//设置package包名称以及导入依赖的类
package com.sbuljat.mailgunner.json
import com.sbuljat.mailgunner.model.SendMessageRequest
import spray.httpx.SprayJsonSupport
import spray.json._
trait SendMessageRequestJsonProtocol extends DefaultJsonProtocol with SprayJsonSupport{
def getOptionStringField(name:String, obj:JsObject): Option[String] = {
obj.getFields(name) match {
case Seq(JsString(x)) => Some(x)
case _ => None
}
}
implicit object SendMessageRequestJsonFormat extends RootJsonFormat[SendMessageRequest] {
def write(req:SendMessageRequest) = JsObject(
"id" -> JsString(req.id),
"to" -> JsString(req.to),
"subject" -> JsString(req.subject),
"body" -> JsString(req.body),
"template" -> req.template.map(e => JsString(e)).getOrElse(JsNull)
)
def read(value:JsValue):SendMessageRequest = {
value.asJsObject.getFields("to", "subject", "body") match {
case Seq(JsString(to), JsString(subject), JsString(body)) =>
val vars:Map[String,String] = value.asJsObject.getFields("vars") match {
case Seq(vars) =>
vars.asJsObject.fields.collect{ case (name:String,value:JsString) => name -> value}.map(e => e._1 -> e._2.value)
case _ =>
Map.empty
}
SendMessageRequest(to, subject, body, getOptionStringField("template", value.asJsObject), vars)
case _ =>
throw new DeserializationException("Bad JSON! Expected { to:String, subject:String, body:String, template:String? }")
}
}
}
}
开发者ID:sbuljat,项目名称:mailgunner,代码行数:47,代码来源:SendMessageRequestJsonProtocol.scala
示例8: CreditServiceActor
//设置package包名称以及导入依赖的类
package org.mireynol.credit.service
import akka.actor.Actor
import org.mireynol.credit.model.Approval
import org.mireynol.rules.api.RulesService
import org.mireynol.rules.drools.ClasspathDroolsRulesService
import spray.httpx.SprayJsonSupport
import spray.routing.HttpService
class CreditServiceActor extends Actor with CreditService {
def actorRefFactory = context
def receive = {
runRoute( applicationRoute )
}
}
trait CreditService extends HttpService with SprayJsonSupport {
import spray.http.MediaTypes._
import org.mireynol.credit.model.Application
import org.mireynol.credit.model.ApplicationJSONFormat.applicationFormat
import org.mireynol.credit.model.Approval
import org.mireynol.credit.model.ApprovalJSONFormat.approvalFormat
val rulesService : RulesService = new ClasspathDroolsRulesService( )
val applicationRoute = path( "applications" ) {
post {
respondWithMediaType( `application/json` )
entity( as[ Application ] ) { application =>
detach() {
val results = rulesService.execute( "credit-approval-ksession", None, List( application ),classOf[ Approval ] ).asInstanceOf[ List[ Approval ] ]
complete( results(0) )
}
}
}
}
}
开发者ID:reynoldsm88,项目名称:scala-drools,代码行数:43,代码来源:CreditService.scala
示例9: GremlinTests
//设置package包名称以及导入依赖的类
import one.gzero.db.{GraphSONEdge, GremlinResultJsonProtocol, GraphSONVertex}
import org.scalatest._
import spray.json._
import spray.httpx.SprayJsonSupport
import SprayJsonSupport._
class GremlinTests extends FlatSpec with Matchers {
case class NameProperty(name:String)
import GremlinResultJsonProtocol._
"A GraphSON object" should "be convertible to a GraphSONEdge with correct label" in {
val edgeJson = JsObject("inVLabel"->JsString("vehicle"),"outV"->JsNumber(8256),"label"->JsString("drove"),"outVLabel"->JsString("person"),"id"->JsString("2rs-6dc-4r9-6hs"),"type"->JsString("edge"),"inV"->JsNumber(8416))
val edge = edgeJson.convertTo[GraphSONEdge]
edge.inV should be (8416)
edge.outV should be (8256)
edge.label should be ("drove")
}
it should "be convertible to a GraphSONVertex with correct name property " in {
implicit val gresult = jsonFormat1(NameProperty)
val vJ = JsObject("label"->JsString("vehicle"),"id"->JsNumber(2),"type"->JsString("vertex"), "properties" -> JsObject("name"->JsString("1932 Ford V-8 B-400 convertible sedan")))
val v = vJ.convertTo[GraphSONVertex]
v.label should be ("vehicle")
v.id.get should be (2)
val name = v.properties.get.convertTo[NameProperty]
name.name should be ("1932 Ford V-8 B-400 convertible sedan")
}
}
开发者ID:gzeroone,项目名称:gzero,代码行数:32,代码来源:GremlinTests.scala
示例10: EndpointServiceSpec
//设置package包名称以及导入依赖的类
package me.zup.simpleEndpoint
import org.scalatest.FunSpec
import org.scalatest.Matchers
import spray.http._
import spray.json._
import StatusCodes._
import spray.httpx.SprayJsonSupport
import spray.testkit.ScalatestRouteTest
import spray.routing.HttpService
import me.zup.simpleEndpoint.AppConfig._
class EndpointServiceSpec extends FunSpec
with Matchers
with ScalatestRouteTest
with PayloadGenerator {
def actorRefFactory = system
describe("Endpoint service operations:") {
import me.zup.simpleEndpoint.DotJsonProtocol._
import me.zup.simpleEndpoint.PayloadJsonProtocol._
import SprayJsonSupport._
val jsonContent = jp.toJson.prettyPrint
val xmlContent = xp.toString
describe("GET") {
it("should return a JSON with specific payload size") {
Get("/json/p") ~> routes ~> check {
val r = responseAs[String]
status should be(OK)
assert(r === jsonContent)
}
}
it("should return a XML with specific payload size") {
Get("/xml/p") ~> routes ~> check {
val r = responseAs[String]
status should be(OK)
assert(r === xmlContent)
}
}
}
}
}
开发者ID:r0qs,项目名称:simple-endpoint,代码行数:47,代码来源:EndpointServiceSpec.scala
示例11: getGuildInfoFromWowProgress
//设置package包名称以及导入依赖的类
package wow.crawler
import spray.client.pipelining._
import spray.httpx.SprayJsonSupport
import spray.httpx.SprayJsonSupport._
import wow.dto.WowGuild
import wow.dto.WowGuildProtocol._
trait WowGuildApi extends SendReceiveClient {
import system.dispatcher
def getGuildInfoFromWowProgress() = {
val pipeline = sendAndReceive
pipeline {
Get(WowUrls.wowProgressMaghteridon)
}
}
def getGuildMembers(guildName: String) = {
val pipeline = sendAndReceive ~> unmarshal[WowGuild]
val encodedGuildName = WowUrls.encodeParam(guildName)
pipeline {
Get(WowUrls.guildMembers.format(encodedGuildName))
}
}
}
object WowGuildApiImpl extends WowGuildApi
开发者ID:MeMpy,项目名称:wow-characters,代码行数:30,代码来源:WowGuildApi.scala
注:本文中的spray.httpx.SprayJsonSupport类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论