本文整理汇总了Scala中org.json4s.jackson.JsonMethods类的典型用法代码示例。如果您正苦于以下问题:Scala JsonMethods类的具体用法?Scala JsonMethods怎么用?Scala JsonMethods使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JsonMethods类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: HTTP_METHOD
//设置package包名称以及导入依赖的类
package net.cimadai.chatwork
import com.ning.http.client.Response
import dispatch.Defaults._
import dispatch._
import org.json4s._
import org.json4s.jackson.JsonMethods
import scala.concurrent.duration._
import scala.concurrent.{Await, TimeoutException}
trait HttpClient extends JsonMethods {
object HTTP_METHOD extends Enumeration {
val GET, POST, PUT, DELETE = Value
}
private val absoluteTimeout = 30.seconds
protected val StatusCodeUndefined = -1
implicit val formats = DefaultFormats
private val http = new Http
private def executeRequestAndAwait(uri: String, method: HTTP_METHOD.Value, params: Params): Option[Response] = {
try {
val req = url(uri).setMethod(method.toString).setParameters(params)
if (method != HTTP_METHOD.GET) {
req.addHeader("Content-Type", "application/x-www-form-urlencoded")
}
val res = Await.result(http(decorateRequest(req)), absoluteTimeout)
Option(res)
} catch {
case e: TimeoutException =>
None
}
}
}
开发者ID:cimadai,项目名称:chatwork-scala,代码行数:40,代码来源:HttpClient.scala
示例2: EncodingBenchmarkSpec
//设置package包名称以及导入依赖的类
package io.circe.benchmarks
import argonaut.Parse
import argonaut.Argonaut._
import org.json4s.jackson.JsonMethods
import org.scalatest.FlatSpec
class EncodingBenchmarkSpec extends FlatSpec with VersionSpecificEncodingSpec {
val benchmark: EncodingBenchmark = new EncodingBenchmark
import benchmark._
def decodeInts(json: String): Option[List[Int]] =
Parse.decodeOption[List[Int]](json)
def decodeFoos(json: String): Option[Map[String, Foo]] =
Parse.decodeOption[Map[String, Foo]](json)
"The encoding benchmark" should "correctly encode integers using Circe" in {
assert(decodeInts(encodeIntsCirce.noSpaces) === Some(ints))
}
it should "correctly encode integers using Argonaut" in {
assert(decodeInts(encodeIntsArgonaut.nospaces) === Some(ints))
}
it should "correctly encode integers using Spray JSON" in {
assert(decodeInts(encodeIntsSpray.compactPrint) === Some(ints))
}
it should "correctly encode integers using Json4s" in {
assert(decodeInts(JsonMethods.compact(encodeIntsJson4s)) === Some(ints))
}
it should "correctly encode integers using Jackson" in {
assert(decodeInts(mapper.writeValueAsString(encodeIntsJackson)) === Some(ints))
}
it should "correctly encode case classes using Circe" in {
assert(decodeFoos(encodeFoosCirce.noSpaces) === Some(foos))
}
it should "correctly encode case classes using Argonaut" in {
assert(decodeFoos(encodeFoosArgonaut.nospaces) === Some(foos))
}
it should "correctly encode case classes using Spray JSON" in {
assert(decodeFoos(encodeFoosSpray.compactPrint) === Some(foos))
}
it should "correctly encode case classes using Json4s" in {
assert(decodeFoos(JsonMethods.compact(encodeFoosJson4s)) === Some(foos))
}
it should "correctly encode case classes using Jackson" in {
assert(decodeFoos(mapper.writeValueAsString(encodeFoosJackson)) === Some(foos))
}
}
开发者ID:circe,项目名称:circe-benchmarks,代码行数:59,代码来源:EncodingBenchmarkSpec.scala
示例3: MnemonicCodeSpec
//设置package包名称以及导入依赖的类
package fr.acinq.syscoin
import java.io.InputStreamReader
import org.json4s.DefaultFormats
import org.json4s.jackson.JsonMethods
import org.junit.runner.RunWith
import org.scalatest.FlatSpec
import org.scalatest.junit.JUnitRunner
object MnemonicCodeSpec {
case class TestVectors(english: Array[Array[String]])
}
@RunWith(classOf[JUnitRunner])
class MnemonicCodeSpec extends FlatSpec {
import MnemonicCode._
import MnemonicCodeSpec._
"MnemonicCode" should "pass reference tests" in {
implicit val format = DefaultFormats
val stream = classOf[MnemonicCodeSpec].getResourceAsStream("/bip39_vectors.json")
val vectors = JsonMethods.parse(new InputStreamReader(stream)).extract[TestVectors]
vectors.english.map(_ match {
case Array(raw, mnemonics, seed) =>
assert(toMnemonics(BinaryData(raw)).mkString(" ") === mnemonics)
assert(toSeed(toMnemonics(BinaryData(raw)), "TREZOR") === BinaryData(seed))
})
}
}
开发者ID:sidhujag,项目名称:syscoin-lib,代码行数:35,代码来源:MnemonicCodeSpec.scala
示例4: SighashSpec
//设置package包名称以及导入依赖的类
package fr.acinq.syscoin.reference
import java.io.InputStreamReader
import fr.acinq.syscoin._
import org.json4s.DefaultFormats
import org.json4s.JsonAST.{JInt, JString, JValue}
import org.json4s.jackson.JsonMethods
import org.junit.runner.RunWith
import org.scalatest.FlatSpec
import org.scalatest.junit.JUnitRunner
@RunWith(classOf[JUnitRunner])
class SighashSpec extends FlatSpec {
implicit val format = DefaultFormats
"syscoin-lib" should "pass reference client sighash tests" in {
val stream = classOf[Base58Spec].getResourceAsStream("/data/sighash.json")
val json = JsonMethods.parse(new InputStreamReader(stream))
// use tail to skip the first line of the .json file
json.extract[List[List[JValue]]].tail.map(_ match {
case JString(raw_transaction) :: JString(script) :: JInt(input_index) :: JInt(hashType) :: JString(signature_hash) :: Nil => {
val tx = Transaction.read(raw_transaction)
val hash = Transaction.hashForSigning(tx, input_index.intValue, fromHexString(script), hashType.intValue)
assert(toHexString(hash.reverse) === signature_hash)
}
case _ => println("warning: could not parse sighash.json properly!")
})
}
}
开发者ID:sidhujag,项目名称:syscoin-lib,代码行数:31,代码来源:SighashSpec.scala
示例5: JsonSituation
//设置package包名称以及导入依赖的类
package org.cddcore.json
import org.cddcore.structure.{PathRootAndSteps, Situation, Structure}
import org.json4s.jackson.{JsonMethods, Serialization}
import org.json4s.{DefaultFormats, JValue}
/** To use this you probably need to
import JsonSituation._
*/
class JsonSituation (implicit structure: Structure[JValue]) extends Situation[JValue] {
def parse(s: String)(implicit formats: DefaultFormats = DefaultFormats) = root(JsonMethods.parse(s))
}
object JsonSituation {
implicit object JsonStructure extends Structure[JValue] {
override def findResult(pathRootAndSteps: PathRootAndSteps[JValue]): Iterable[JValue] = {
import pathRootAndSteps._
List(steps.foldLeft(root: JValue) { case (acc, step) =>
step.linked match {
case true => acc \ step.element
case false => acc \\ step.element
}
})
}
override def structureTitle: String = "json"
override def sToString(s: JValue): String = {
implicit val formats = DefaultFormats
Serialization.writePretty(s)
}
}
}
开发者ID:phil-rice,项目名称:CddCore2,代码行数:40,代码来源:Json.scala
示例6: Json
//设置package包名称以及导入依赖的类
package com.paypal.risk.smunf.util
import org.json4s.DefaultFormats
import org.json4s.Extraction
import org.json4s.jackson.JsonMethods
object Json {
def toJsonString(in: Any): String = {
implicit val formats = DefaultFormats
JsonMethods.compact(JsonMethods.render(Extraction.decompose(in)))
}
def toPrettyJsonString(in: Any): String = {
implicit val formats = DefaultFormats
JsonMethods.pretty(JsonMethods.render(Extraction.decompose(in)))
}
}
开发者ID:yanlzhang8936,项目名称:Smunf,代码行数:19,代码来源:Json.scala
示例7: AuditSerializer
//设置package包名称以及导入依赖的类
package com.paypal.risk.smunf.audit
import org.apache.spark.rdd.RDD
import org.json4s._
import org.json4s.jackson.JsonMethods
import org.json4s.JsonDSL._
object AuditSerializer {
def jsonizeMatchAuditResult(
data: RDD[MatchAuditResult],
pretty: Boolean = true): String = {
val local = data.collect().toSeq
val matchResultJson =
("matchAuditResult" -> local.map{v =>
( ("variableId" -> v.variableId) ~
("numMissingMatch" -> v.numMissingMatch) ~
("numExactMatch" -> v.numExactMatch) ~
("numLowerMatch" -> v.numLowerMatch) ~
("numAbsoluteMatch" -> v.numAbsoluteMatch) ~
("numRelativeMatch" -> v.numRelativeMatch) ~
("numStdMatch" -> v.numStdMatch) ~
("numAnyMatch" -> v.numAnyMatch) ~
("numTotalCount" -> v.numTotalCount) ~
("rateExactMatch" -> v.rateExactMatch) ~
("rateNonMissExactMatch" -> v.rateNonMissExactMatch) ~
("rateLowerMatch" -> v.rateLowerMatch) ~
("rateNonMissLowerMatch" -> v.rateNonMissLowerMatch) ~
("rateEpsilonMatch" -> v.rateAbsoluteMatch) ~
("rateStdMatch" -> v.rateStdMatch) ~
("rateAnyMatch" -> v.rateAnyMatch) ~
("rateNonMissAnyMatch" -> v.rateNonMissAnyMatch))})
if (pretty) JsonMethods.pretty(JsonMethods.render(matchResultJson))
else JsonMethods.compact(JsonMethods.render(matchResultJson))
}
}
开发者ID:yanlzhang8936,项目名称:Smunf,代码行数:38,代码来源:AuditSerializer.scala
示例8: FormElementSpec
//设置package包名称以及导入依赖的类
package com.yukimt.scrape.element
import org.specs2.mutable.Specification
import org.openqa.selenium.htmlunit.HtmlUnitDriver
import org.json4s.JObject
import org.json4s.jackson.JsonMethods
import ParserMethod._
import ElementMethod._
class FormElementSpec extends Specification{
sequential
implicit val driver = new HtmlUnitDriver(true)
driver.get("http://localhost:3000/view")
val parser = new Parser(driver)
var element = (parser >> css("form")) >> asForm
"FormElement" should {
"set query string" in {
element.setQueryString(Map("a"->"b", "c"->"d"))
element >> url === "/form?a=b&c=d"
}
"submit" in {
driver.getTitle === "Express Sample Title"
element.submit
driver.getTitle === ""
}
"add form data" in {
driver.navigate.back
element = (parser >> css("form")) >> asForm
driver.getTitle === "Express Sample Title"
element.addFormData("abc", "def")
element.submit
driver.getTitle === ""
val result = JsonMethods.parse(driver.getPageSource.replaceAll("<.+>", "")).asInstanceOf[JObject].values.asInstanceOf[Map[String, String]]
result === Map("text"->"default","textarea"->"","fruit"->"a","select"->"select1","abc"->"def")
}
"set uri" in {
driver.navigate.back
element = (parser >> css("form")) >> asForm
element.setUri("/abc")
element >> url === "/abc"
}
}
}
开发者ID:yuki-mt,项目名称:scraper4s,代码行数:48,代码来源:FormElementSpec.scala
注:本文中的org.json4s.jackson.JsonMethods类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论