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

Scala JInt类代码示例

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

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



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

示例1: MongoQueryParser

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

import org.json4s.JsonAST.JBool
import org.json4s.JsonAST.JDecimal
import org.json4s.JsonAST.JDouble
import org.json4s.JsonAST.JInt
import org.json4s.JsonAST.JObject
import org.json4s.JsonAST.JString
import org.json4s.native.JsonMethods
import org.mongodb.scala.bson.collection.immutable.Document


class MongoQueryParser {

  def parse(query: String): Document = {
    val json = JsonMethods.parse(query, useBigDecimalForDouble = true)
    val mongoQuery: List[Document] =
      for {
        JObject(child) <- json
        (fieldName, value) <- child
      } yield {
        value match {
          case JString(s) => Document(fieldName -> s)
          case JDouble(num) => Document(fieldName -> num)
          case JDecimal(num) => Document(fieldName -> num)
          case JInt(num) => Document(fieldName -> num.intValue())
          case JBool(bool) => Document(fieldName -> bool)
          case _ => throw new IllegalArgumentException(f"Error when processing field '$fieldName%s': Unsupported type: '$value'")
        }
      }
    mongoQuery.reduce(_ ++ _)
  }
} 
开发者ID:dougsleite,项目名称:oak,代码行数:34,代码来源:MongoQueryParser.scala


示例2: 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


示例3: CustomSerializers

//设置package包名称以及导入依赖的类
package com.miguelisasmendi.serializers

import java.sql.Timestamp

import org.json4s.CustomSerializer
import org.json4s.JsonAST.{JInt, JNull}

object CustomSerializers {
  val all = List(CustomTimestampSerializer)
}

case object CustomTimestampSerializer extends CustomSerializer1653285780(format =>
  ({
    case JInt(x) => new Timestamp(x.longValue * 1000)
    case JNull => null
  },
    {
      case date: Timestamp => JInt(date.getTime / 1000)
    })) 
开发者ID:miguel-isasmendi,项目名称:example-scala-akka,代码行数:20,代码来源:CustomerSerializers.scala


示例4: TimestampSerializer

//设置package包名称以及导入依赖的类
package articlestreamer.shared.marshalling

import java.sql.Timestamp

import articlestreamer.shared.exception.exceptions._
import com.typesafe.scalalogging.LazyLogging
import org.json4s.JsonAST.{JInt, JLong}
import org.json4s.{CustomSerializer, NoTypeHints, native}

trait CustomJsonFormats extends LazyLogging {

  val dformat: String = "yyyy-MM-dd hh:mm:ss"

  case object TimestampSerializer extends CustomSerializer[java.sql.Timestamp](format => (
    {
      case JInt(l) =>
        try {
          new Timestamp(l.toLong)
        } catch {
          case ex: Throwable => {
            logger.error(s"Error while parsing date : ${ex.getStackTraceAsString}")
            null
          }
        }
      case JLong(l) =>
        try {
          new Timestamp(l)
        } catch {
          case ex: Throwable => {
            logger.error(s"Error while parsing date : ${ex.getStackTraceAsString}")
            null
          }
        }
      case _ => null
    },
    {
      case ts: Timestamp =>
        JLong(ts.getTime)
    }
    )
  )

  implicit val json4sFormats =  native.Serialization.formats(NoTypeHints) + TimestampSerializer

} 
开发者ID:firens,项目名称:article-streamer,代码行数:46,代码来源:CustomJsonFormats.scala


示例5: DataPoint

//设置package包名称以及导入依赖的类
package com.criteo.slab.lib.graphite

import com.criteo.slab.utils.Jsonable
import org.json4s.JsonAST.{JArray, JDouble, JInt, JNull}
import org.json4s.{CustomSerializer, Serializer}

private[slab] case class DataPoint(value: Option[Double], timestamp: Long)

object DataPoint {

  implicit object ToJSON extends Jsonable[DataPoint] {
    override val serializers: Seq[Serializer[_]] = List(Ser)

    object Ser extends CustomSerializer[DataPoint](_ => ( {
      case JArray(JDouble(value) :: JInt(date) :: Nil) =>
        DataPoint(Some(value), date.toLong)
      case JArray(JNull :: JInt(date) :: Nil) =>
        DataPoint(None, date.toLong)
    }, {
      case DataPoint(value, date) =>
        val v = value match {
          case Some(v) => JDouble(v)
          case None => JNull
        }
        JArray(
          List(
            v,
            JInt(date)
          )
        )
    }
    ))

  }

}

private[slab] case class GraphiteMetric(
                                         target: String,
                                         datapoints: List[DataPoint]
                                       )

object GraphiteMetric {

  implicit object ToJSON extends Jsonable[GraphiteMetric] {
    override val serializers: Seq[Serializer[_]] = implicitly[Jsonable[DataPoint]].serializers
  }

} 
开发者ID:criteo,项目名称:slab,代码行数:50,代码来源:GraphiteMetric.scala



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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