当前位置: 首页>>代码示例>>Scala>>正文


Scala JsonCodec类代码示例

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


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

示例1: LeanUser

//设置package包名称以及导入依赖的类
package xyz.ariwaranosai.leancloud.LeanModel

import io.circe.generic.JsonCodec


@JsonCodec case class LeanUser(
                      username: String, password: String,
                      phone: Option[String] = None, mobilePhoneVerified: Option[Boolean] = None,
                      email: Option[String] = None, emailVerified: Option[Boolean] = None,
                      sessionToken: Option[String] = None, salt: Option[String] = None
                    )


@JsonCodec case class UserCreateResponse(
                         sessionToken: String,
                         createdAt: String,
                         objectId: String
                         ) 
开发者ID:ariwaranosai,项目名称:Hikikumari,代码行数:19,代码来源:UserModel.scala

示例2: User

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

import java.time.LocalDateTime
import java.util.UUID

import io.circe.generic.JsonCodec
import io.circe.java8.time._

@JsonCodec case class User (
   id: UUID = UUID.randomUUID,
   name: String,
   email: String,
   pass: String,
   deleted: Boolean = false,
   created: LocalDateTime = LocalDateTime.now(),
   modified: LocalDateTime = LocalDateTime.now()
 )  extends BaseModel {
  def delete: User = copy(deleted = true)
}

object User {
  def apply(
             name: String,
             email: String,
             pass: String
           ): User = new User(name = name, email = email, pass = pass)
} 
开发者ID:mpetrone,项目名称:scala-functional-rest-api,代码行数:28,代码来源:User.scala

示例3: AccountEndpoint

//设置package包名称以及导入依赖的类
package aecor.example

import aecor.example.MonixSupport._
import aecor.example.domain.account.{ AccountAggregate, AccountId }
import akka.http.scaladsl.model.StatusCodes
import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.server.Route
import cats.implicits._
import de.heikoseeberger.akkahttpcirce.FailFastCirceSupport._
import io.circe.generic.JsonCodec
import monix.eval.Task
import AnyValCirceEncoding._
import aecor.example.AccountEndpoint.AccountApiRequest.OpenAccountRequest

class AccountEndpoint(account: AccountAggregate[Task]) {

  def openAccount(accountId: AccountId): Task[String Either Unit] =
    account
      .openAccount(accountId)
      .map(_.leftMap(_.toString))
}

object AccountEndpoint {

  sealed abstract class AccountApiRequest
  object AccountApiRequest {
    @JsonCodec final case class OpenAccountRequest(accountId: AccountId) extends AccountApiRequest
  }

  def route(api: AccountEndpoint): Route =
    pathPrefix("account") {
      post {
        (path("open") & entity(as[AccountApiRequest.OpenAccountRequest])) {
          case OpenAccountRequest(accountId) =>
            complete {
              api.openAccount(accountId).map {
                case Left(e) => StatusCodes.BadRequest -> e.toString
                case Right(result) => StatusCodes.OK -> ""
              }
            }
        }
      }
    }
} 
开发者ID:notxcain,项目名称:aecor,代码行数:45,代码来源:AccountEndpoint.scala

示例4: PositionSide

//设置package包名称以及导入依赖的类
package com.msilb.scalandav20.model

import com.msilb.scalandav20.model.pricing.PriceValue
import com.msilb.scalandav20.model.primitives.{AccountUnits, DecimalNumber, InstrumentName}
import com.msilb.scalandav20.model.trades.TradeID
import io.circe.generic.JsonCodec

package object positions {

  @JsonCodec
  case class PositionSide(units: DecimalNumber,
                          averagePrice: Option[PriceValue],
                          tradeIDs: Option[Seq[TradeID]],
                          pl: AccountUnits,
                          unrealizedPL: Option[AccountUnits],
                          resettablePL: AccountUnits)

  @JsonCodec
  case class Position(instrument: InstrumentName,
                      pl: AccountUnits,
                      unrealizedPL: Option[AccountUnits],
                      resettablePL: AccountUnits,
                      long: PositionSide,
                      short: PositionSide)

  @JsonCodec
  case class CalculatedPositionState(instrument: InstrumentName,
                                     netUnrealizedPL: AccountUnits,
                                     longUnrealizedPL: AccountUnits,
                                     shortUnrealizedPL: AccountUnits)

} 
开发者ID:msilb,项目名称:scalanda-v20,代码行数:33,代码来源:package.scala

示例5: Request

//设置package包名称以及导入依赖的类
package com.msilb.scalandav20.client

import com.msilb.scalandav20.model.orders.OrderRequest
import com.msilb.scalandav20.model.trades.ClientExtensions
import com.msilb.scalandav20.model.transactions.{StopLossDetails, TakeProfitDetails, TrailingStopLossDetails}
import io.circe.generic.JsonCodec

sealed trait Request

object Request {

  @JsonCodec
  case class AccountConfigChangeRequest(alias: Option[String] = None,
                                        marginRate: Option[String] = None) extends Request

  @JsonCodec
  case class CreateOrderRequest(order: OrderRequest) extends Request

  @JsonCodec
  case class ReplaceOrderRequest(order: OrderRequest) extends Request

  @JsonCodec
  case class OrderClientExtensionsModifyRequest(clientExtensions: Option[ClientExtensions] = None,
                                                tradeClientExtensions: Option[ClientExtensions] = None) extends Request

  @JsonCodec
  case class CloseTradeRequest(units: String = "ALL") extends Request

  @JsonCodec
  case class TradeClientExtensionsModifyRequest(clientExtensions: ClientExtensions) extends Request

  @JsonCodec
  case class TradesDependentOrdersModifyRequest(takeProfit: Option[TakeProfitDetails] = None,
                                                stopLoss: Option[StopLossDetails] = None,
                                                trailingStopLoss: Option[TrailingStopLossDetails] = None) extends Request

  @JsonCodec
  case class ClosePositionRequest(longUnits: Option[String] = None,
                                  longClientExtensions: Option[ClientExtensions] = None,
                                  shortUnits: Option[String] = None,
                                  shortClientExtensions: Option[ClientExtensions] = None) extends Request

} 
开发者ID:msilb,项目名称:scalanda-v20,代码行数:44,代码来源:Request.scala

示例6: Json

//设置package包名称以及导入依赖的类
// Copyright 2016 flat authors

package flat.examples.json

import flat._
import io.circe.generic.JsonCodec
import io.circe.syntax._

object Json extends App with FlatApp {
  @JsonCodec case class Point(x: Double, y: Double)
  app.get("/point") { request =>
    val point = Point(0, 0)
    Ok(point.asJson)
  }

  @JsonCodec case class Circle(label: String, radius: Double, point: Point)
  app.get("/circle") { request =>
    val circle = Circle("unit", 1, Point(0, 0))
    Ok(circle.asJson)
  }

  @JsonCodec case class Polygon(points: List[Point])
  app.get("/square") { request =>
    val square = Polygon(List(
      Point(1, 1),
      Point(1, -1),
      Point(-1, -1),
      Point(-1, 1)
    ))
    Ok(square.asJson)
  }

  app.start
} 
开发者ID:keithblaha,项目名称:flat,代码行数:35,代码来源:Json.scala

示例7: NodeMetadata

//设置package包名称以及导入依赖的类
package maml.ast.metadata

import maml.ast.codec._
import maml.ast.utility._

import io.circe.generic.JsonCodec


@JsonCodec
case class NodeMetadata(
  label: Option[String] = None,
  description: Option[String] = None,
  histogram: Option[Histogram] = None,
  colorRamp: Option[Vector[Int]] = None,
  classMap: Option[ClassMap] = None,
  breaks: Option[Vector[Double]] = None
) {

  
  def fallbackTo(that: NodeMetadata): NodeMetadata = {
    NodeMetadata(
      this.label.orElse(that.label),
      this.description.orElse(that.description),
      this.histogram.orElse(that.histogram),
      this.colorRamp.orElse(that.colorRamp),
      this.classMap.orElse(that.classMap)
    )
  }
} 
开发者ID:geotrellis,项目名称:maml,代码行数:30,代码来源:NodeMetadata.scala

示例8: Item

//设置package包名称以及导入依赖的类
package sample.algebra

import endpoints.documented.algebra.{BasicAuthentication, Endpoints, CirceEntities, OptionalResponses}
import io.circe.generic.JsonCodec

trait DocumentedApi
  extends Endpoints
    with OptionalResponses
    with BasicAuthentication
    with CirceEntities {

  val items =
    endpoint(
      get(path / "items" / segment[String]("category") /? optQs[Int]("page")),
      jsonResponse[List[Item]]("List all the items of the given category")
    )

  val itemId = segment[String]("id")

  val item =
    endpoint(
      get(path / "item" / itemId),
      option(jsonResponse[Item]("The item identified by 'id'"), "Item not found")
    )

  val admin =
    authenticatedEndpoint(
      Get,
      path / "admin",
      emptyRequest,
      emptyResponse("Administration page"),
      "Authentication error"
    )

}

@JsonCodec
case class Item(name: String) 
开发者ID:julienrf,项目名称:endpoints,代码行数:39,代码来源:DocumentedApi.scala


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