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

Scala Encoder类代码示例

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

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



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

示例1: route

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

import akka.http.scaladsl.marshalling.{Marshal, ToEntityMarshaller}
import akka.http.scaladsl.model.{HttpHeader, HttpResponse, ResponseEntity, StatusCode}
import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.server.Route
import com.typesafe.config.ConfigFactory
import com.ulasakdeniz.hakker.template.Render
import de.heikoseeberger.akkahttpcirce.CirceSupport._
import io.circe.{Encoder, Json}
import io.circe.syntax._

import scala.collection.immutable
import scala.concurrent.ExecutionContext

trait Controller extends Render {

  override lazy val config = ConfigFactory.load()
  val StatusCodes          = akka.http.scaladsl.model.StatusCodes

  def route: Route

  def apply(): Route = {
    get {
      // render frontend files
      pathPrefix("js") {
        renderDir("js")
      }
    } ~ route
  }

  def send(statusCode: StatusCode): Route = complete(statusCode)

  def send[T](statusCode: StatusCode, content: T, headers: immutable.Seq[HttpHeader] = Nil)(
      implicit marshaller: ToEntityMarshaller[T],
      ec: ExecutionContext): Route = {
    val response = Marshal(content)
      .to[ResponseEntity](marshaller, ec)
      .map(entity => {
        HttpResponse(statusCode, headers = headers).withEntity(entity)
      })
    complete(response)
  }

  def sendJson[T](statusCode: StatusCode, content: T)(implicit encoder: Encoder[T],
                                                      ec: ExecutionContext): Route = {
    sendJson(statusCode, content.asJson)
  }

  def sendJson[T](content: T)(implicit encoder: Encoder[T], ec: ExecutionContext): Route = {
    sendJson(StatusCodes.OK, content)
  }

  def sendJson(statusCode: StatusCode, json: Json)(implicit ec: ExecutionContext): Route = {
    send(statusCode, Option(json.noSpaces))
  }
} 
开发者ID:ulasakdeniz,项目名称:hakker,代码行数:58,代码来源:Controller.scala


示例2: RootDecoder

//设置package包名称以及导入依赖的类
package io.circe.spray

import io.circe.{ Decoder, Encoder, RootEncoder }


case class RootDecoder[A](underlying: Decoder[A])

final object RootDecoder extends LowPriorityRootDecoders {
  implicit def rootDecoderWithRootEncoder[A](implicit decoder: Decoder[A], encoder: RootEncoder[A]): RootDecoder[A] =
    RootDecoder(decoder)
}

private[spray] sealed class LowPriorityRootDecoders {
  implicit def rootDecoderBlocker1[A](implicit decoder: Decoder[A], encoder: Encoder[A]): RootDecoder[A] =
    RootDecoder(decoder)
  implicit def rootDecoderBlocker2[A](implicit decoder: Decoder[A], encoder: Encoder[A]): RootDecoder[A] =
    RootDecoder(decoder)
  implicit def rootDecoder[A](implicit decoder: Decoder[A]): RootDecoder[A] = RootDecoder(decoder)
} 
开发者ID:travisbrown,项目名称:circe-spray,代码行数:20,代码来源:RootDecoder.scala


示例3: anyValEncoder

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

import io.circe.{ Decoder, Encoder }
import shapeless.Unwrapped

trait AnyValCirceEncoding {
  implicit def anyValEncoder[V, U](implicit ev: V <:< AnyVal,
                                   V: Unwrapped.Aux[V, U],
                                   encoder: Encoder[U]): Encoder[V] = {
    val _ = ev
    encoder.contramap(V.unwrap)
  }

  implicit def anyValDecoder[V, U](implicit ev: V <:< AnyVal,
                                   V: Unwrapped.Aux[V, U],
                                   decoder: Decoder[U]): Decoder[V] = {
    val _ = ev
    decoder.map(V.wrap)
  }
}

object AnyValCirceEncoding extends AnyValCirceEncoding

object CirceSupport
    extends de.heikoseeberger.akkahttpcirce.FailFastCirceSupport
    with AnyValCirceEncoding 
开发者ID:notxcain,项目名称:aecor,代码行数:27,代码来源:AnyValCirceEncoding.scala


示例4: FormSettings

//设置package包名称以及导入依赖的类
package org.danielnixon.progressive.shared.api

import io.circe.{ Decoder, Encoder }
import io.circe.generic.semiauto.{ deriveDecoder, deriveEncoder }
import org.danielnixon.progressive.shared.Wart

final case class FormSettings(
  ajax: Boolean = true,
  target: Option[Target] = None,
  refreshTarget: Option[Target] = Some(Target.ClosestRefresh),
  busyMessage: Option[String] = None,
  focusTarget: Boolean = true,
  reloadPage: Boolean = false,
  confirmMessage: Option[String] = None,
  confirmedAction: Option[String] = None,
  ajaxAction: Option[String] = None,
  remove: Boolean = false,
  resetForm: Boolean = false
)

@SuppressWarnings(Array(Wart.Nothing))
object FormSettings {
  implicit val decoder: Decoder[FormSettings] = deriveDecoder[FormSettings]
  implicit val encoder: Encoder[FormSettings] = deriveEncoder[FormSettings]

  def asJson(target: FormSettings): String = Json.asJson(target)

  def fromJson(json: String): Option[FormSettings] = Json.fromJson(json)
} 
开发者ID:danielnixon,项目名称:progressive,代码行数:30,代码来源:FormSettings.scala


示例5: LinkSettings

//设置package包名称以及导入依赖的类
package org.danielnixon.progressive.shared.api

import io.circe.{ Decoder, Encoder }
import io.circe.generic.semiauto.{ deriveDecoder, deriveEncoder }
import org.danielnixon.progressive.shared.Wart

final case class LinkSettings(
  target: Target,
  busyMessage: Option[String] = None,
  focusTarget: Boolean = true,
  href: Option[String] = None
)

@SuppressWarnings(Array(Wart.AsInstanceOf, Wart.Nothing))
object LinkSettings {
  implicit val decoder: Decoder[LinkSettings] = deriveDecoder[LinkSettings]
  implicit val encoder: Encoder[LinkSettings] = deriveEncoder[LinkSettings]

  def asJson(target: LinkSettings): String = Json.asJson(target)

  def fromJson(json: String): Option[LinkSettings] = Json.fromJson(json)
} 
开发者ID:danielnixon,项目名称:progressive,代码行数:23,代码来源:LinkSettings.scala


示例6: SubmitButtonSettings

//设置package包名称以及导入依赖的类
package org.danielnixon.progressive.shared.api

import io.circe.{ Decoder, Encoder }
import io.circe.generic.semiauto.{ deriveDecoder, deriveEncoder }
import org.danielnixon.progressive.shared.Wart

final case class SubmitButtonSettings(
  target: Option[Target] = None,
  busyMessage: Option[String] = None
)

@SuppressWarnings(Array(Wart.Nothing))
object SubmitButtonSettings {
  implicit val decoder: Decoder[SubmitButtonSettings] = deriveDecoder[SubmitButtonSettings]
  implicit val encoder: Encoder[SubmitButtonSettings] = deriveEncoder[SubmitButtonSettings]

  def asJson(target: SubmitButtonSettings): String = Json.asJson(target)

  def fromJson(json: String): Option[SubmitButtonSettings] = Json.fromJson(json)
} 
开发者ID:danielnixon,项目名称:progressive,代码行数:21,代码来源:SubmitButtonSettings.scala


示例7: circeableFrameFormat

//设置package包名称以及导入依赖的类
package org.http4s.akka

import io.circe.{Decoder, Encoder, Json}
import io.circe.parser._
import org.http4s.{Charset, DefaultCharset, UrlForm}
import org.http4s.websocket.WebsocketBits._
import play.twirl.api._


  implicit def circeableFrameFormat[A: Encoder : Decoder]: FrameFormatter[A] = jsonFrameFormatter.transform[A](
    Encoder[A].apply(_),
    Decoder[A].decodeJson(_).toTry.get
  )
  
  //=== TWIRL ===
  implicit val htmlFrameFormatter: FrameFormatter[Html] = stringFrameFormatter.transform(_.body, Html.apply)
  implicit val xmlFrameFormatter: FrameFormatter[Xml] = stringFrameFormatter.transform(_.body, Xml.apply)
  implicit val txtFrameFormatter: FrameFormatter[Txt] = stringFrameFormatter.transform(_.body, Txt.apply)
  implicit val javaScriptFrameFormatter: FrameFormatter[JavaScript] = stringFrameFormatter.transform(_.body, JavaScript.apply)
} 
开发者ID:Lasering,项目名称:http4s-akka,代码行数:21,代码来源:FrameFormatter.scala


示例8: yaml

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

import io.circe.yaml._
import io.circe.Encoder
import io.circe.syntax._
import swaggerblocks.internal.models.{ApiObjectSchema, ApiSchemaDefinition}

object yaml {
  implicit class ExampleExtension(schemaDef: ApiSchemaDefinition) {
    private val printer = Printer.spaces2.copy(
      preserveOrder = true,
      dropNullKeys = true
    )

    def withExample[T](obj: T)(implicit encoder: Encoder[T]): ApiSchemaDefinition =
      schemaDef.schema match {
        case s: ApiObjectSchema =>
          schemaDef.copy(
            schema = s.copy(
              example = Some(printer.pretty(obj.asJson))
            )
          )

        case _ =>
          schemaDef
      }
  }
} 
开发者ID:felixbr,项目名称:swagger-blocks-scala,代码行数:29,代码来源:yaml.scala


示例9: apply

//设置package包名称以及导入依赖的类
package swaggerblocks.rendering.yaml

import io.circe.yaml.parser.parse
import io.circe.{Encoder, Json}
import swaggerblocks.internal.specModels._
import cats.syntax.either._

trait SpecEncoders {

  implicit val encodeSpecExample = new Encoder[SpecExample] {
    def apply(se: SpecExample): Json = {
      // Since we control the serialization this should be always valid
      parse(se.value).valueOr(throw _)
    }
  }

  implicit val encodeSpecValue = new Encoder[SpecValue] {
    def apply(sv: SpecValue): Json = sv match {
      case SpecValue.StringValue(v)    => Json.fromString(v)
      case SpecValue.IntValue(v)       => Json.fromInt(v)
      case SpecValue.BooleanValue(v)   => Json.fromBoolean(v)
      case SpecValue.ListValue(list)   => Json.fromValues(list.map(apply))
      case SpecValue.MapValue(mapping) => Json.fromFields(mapping.mapValues(apply))
    }
  }
} 
开发者ID:felixbr,项目名称:swagger-blocks-scala,代码行数:27,代码来源:SpecEncoders.scala


示例10: Event

//设置package包名称以及导入依赖的类
package io.taig.akka.http.phoenix

import io.circe.{ Decoder, Encoder }

sealed case class Event( name: String )

object Event {
    object Close extends Event( "phx_close" )
    object Error extends Event( "phx_error" )
    object Join extends Event( "phx_join" )
    object Reply extends Event( "phx_reply" )
    object Leave extends Event( "phx_leave" )

    val all = Close :: Error :: Join :: Reply :: Leave :: Nil

    implicit val encoderEvent: Encoder[Event] = {
        Encoder[String].contramap( _.name )
    }

    implicit val decoderEvent: Decoder[Event] = {
        Decoder[String].map { name ?
            all.find( _.name == name ).getOrElse( Event( name ) )
        }
    }
} 
开发者ID:Taig,项目名称:akka-http-phoenix,代码行数:26,代码来源:Event.scala


示例11: Topic

//设置package包名称以及导入依赖的类
package io.taig.akka.http.phoenix

import io.circe.{ Decoder, Encoder }
import cats.implicits._

case class Topic( name: String, identifier: Option[String] ) {
    def isSubscribedTo( topic: Topic ): Boolean = topic match {
        case Topic( `name`, `identifier` ) ? true
        case Topic( `name`, None )         ? true
        case _                             ? false
    }

    def serialize = name + identifier.map( ":" + _ ).getOrElse( "" )

    override def toString = s"Topic($serialize)"
}

object Topic {
    implicit val encoderTopic: Encoder[Topic] = {
        Encoder[String].contramap( _.serialize )
    }

    implicit val decoderTopic: Decoder[Topic] = {
        Decoder[String].emap { topic ?
            Either.fromOption( parse( topic ), "Invalid format" )
        }
    }

    val Phoenix = Topic( "phoenix" )

    val Pattern = "(\\w+)(?::(\\w+))?".r

    def apply( name: String, identifier: String ): Topic = {
        Topic( name, Some( identifier ) )
    }

    def apply( name: String ): Topic = Topic( name, None )

    def parse( topic: String ): Option[Topic] = {
        topic match {
            case Pattern( name, identifier ) ?
                Some( Topic( name, Option( identifier ) ) )
            case _ ? None
        }
    }
} 
开发者ID:Taig,项目名称:akka-http-phoenix,代码行数:47,代码来源:Topic.scala


示例12: RefusedByRateLimiterError

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

import com.twitter.finagle.http.{Response, Status}
import com.twitter.finagle.RefusedByRateLimiter
import com.twitter.io.Buf
import com.twitter.logging.Logger
import io.circe.{Decoder, Encoder}
import io.circe.syntax._

final case class RefusedByRateLimiterError(
  message: String
) extends Exception(message) {
  def toResponse: Response = RefusedByRateLimiterError.toResponse(this)
}

object RefusedByRateLimiterError {
  val LOG = Logger.get(getClass)

  implicit val errorEncoder: Encoder[RefusedByRateLimiterError] =
    Encoder.forProduct1("message") { err => err.message }

  implicit val errorDecoder: Decoder[RefusedByRateLimiterError] =
    Decoder.forProduct1[String, RefusedByRateLimiterError]("message") {
      case (message: String) => RefusedByRateLimiterError(message)
    }

  def toResponse(error: RefusedByRateLimiterError): Response = {
    val response = Response(Status.TooManyRequests)
    val content = error.asJson.noSpaces
    LOG.info(content)
    response.content = Buf.Utf8(content)
    response.contentType = "application/json"
    response
  }
} 
开发者ID:lookout,项目名称:rate-limiting-strategy,代码行数:36,代码来源:RefusedByRateLimiterError.scala


示例13: Position

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

import eu.timepit.refined.W
import eu.timepit.refined.api.Refined
import eu.timepit.refined.numeric.Interval
import io.circe.generic.semiauto._
import io.circe.{Decoder, Encoder}
import io.circe.refined._
import kartograffel.shared.model.Position.{Latitude, Longitude}

final case class Position(
    latitude: Latitude,
    longitude: Longitude
)

object Position {
  type Latitude = Double Refined Interval.Closed[W.`-90.0`.T, W.`90.0`.T]

  type Longitude = Double Refined Interval.Closed[W.`-180.0`.T, W.`180.0`.T]

  implicit val positionDecoder: Decoder[Position] =
    deriveDecoder

  implicit val positionEncoder: Encoder[Position] =
    deriveEncoder
} 
开发者ID:fthomas,项目名称:kartograffel,代码行数:27,代码来源:Position.scala


示例14: Graffel

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

import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder}
import io.circe.{Decoder, Encoder}

final case class Graffel(
    id: Graffel.Id,
    position: Position
)

object Graffel {
  final case class Id(value: String) extends AnyVal

  implicit val graffelIdDecoder: Decoder[Id] =
    Decoder.decodeString.map(Id.apply)

  implicit val graffelIdEncoder: Encoder[Id] =
    Encoder.encodeString.contramap(_.value)

  implicit val graffelDecoder: Decoder[Graffel] =
    deriveDecoder

  implicit val graffelEncoder: Encoder[Graffel] =
    deriveEncoder
} 
开发者ID:fthomas,项目名称:kartograffel,代码行数:26,代码来源:Graffel.scala


示例15: EdgeCollection

//设置package包名称以及导入依赖的类
package com.outr.arango.managed

import com.outr.arango.{ArangoCode, ArangoEdge, ArangoException, DocumentOption, Edge}
import com.outr.arango.rest.{CreateInfo, GraphResponse}
import io.circe.Encoder

import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global

abstract class EdgeCollection[T <: Edge with DocumentOption](override val graph: Graph,
                                                             override val name: String,
                                                             from: List[String],
                                                             to: List[String]) extends AbstractCollection[T] {
  private lazy val edge: ArangoEdge = graph.instance.edge(name)

  override def create(waitForSync: Boolean = false): Future[GraphResponse] = edge.create(from, to, waitForSync)
  override def delete(): Future[GraphResponse] = edge.delete(dropCollection = true)

  override def get(key: String): Future[Option[T]] = edge[T](key).map(_.edge).recover {
    case t: ArangoException if t.error.errorCode == ArangoCode.ArangoDocumentNotFound => None
  }

  override protected def insertInternal(document: T): Future[CreateInfo] = {
    edge.insert[T](document).map(_.edge)
  }

  override protected def updateInternal[M](key: String, modification: M)
                                          (implicit encoder: Encoder[M]): Future[CreateInfo] = {
    edge.modify[M](key, modification).map(_.edge)
  }

  override protected def replaceInternal(currentKey: String, document: T): Future[Unit] = {
    edge.replace[T](currentKey, document).map(_ => ())
  }

  override protected def deleteInternal(key: String): Future[Boolean] = edge.delete(key).map(_.removed)
} 
开发者ID:outr,项目名称:scarango,代码行数:38,代码来源:EdgeCollection.scala


示例16: VertexCollection

//设置package包名称以及导入依赖的类
package com.outr.arango.managed

import com.outr.arango._
import com.outr.arango.rest.{CreateInfo, GraphResponse, QueryResponse}
import io.circe.Encoder

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future

abstract class VertexCollection[T <: DocumentOption](override val graph: Graph,
                                                     override val name: String) extends AbstractCollection[T] {
  private lazy val vertex: ArangoVertex = graph.instance.vertex(name)

  override def create(waitForSync: Boolean = false): Future[GraphResponse] = vertex.create(waitForSync)
  override def delete(): Future[GraphResponse] = vertex.delete()

  override def get(key: String): Future[Option[T]] = vertex[T](key).map(_.vertex).recover {
    case t: ArangoException if t.error.errorCode == ArangoCode.ArangoDocumentNotFound => None
  }

  override protected def insertInternal(document: T): Future[CreateInfo] = {
    vertex.insert[T](document, waitForSync = Some(true)).map(_.vertex)
  }

  override protected def updateInternal[M](key: String, modification: M)
                                          (implicit encoder: Encoder[M]): Future[CreateInfo] = {
    vertex.modify[M](key, modification).map(_.vertex)
  }

  override protected def replaceInternal(currentKey: String, document: T): Future[Unit] = {
    vertex.replace[T](currentKey, document).map(_ => ())
  }

  override protected def deleteInternal(key: String): Future[Boolean] = vertex.delete(key).map(_.removed)
} 
开发者ID:outr,项目名称:scarango,代码行数:36,代码来源:VertexCollection.scala


示例17: PolymorphicVertexCollection

//设置package包名称以及导入依赖的类
package com.outr.arango.managed

import com.outr.arango.{DocumentOption, Macros}
import com.outr.arango.rest.CreateInfo
import io.circe.Decoder.Result
import io.circe.{Decoder, Encoder, HCursor, Json}

import scala.language.experimental.macros

class PolymorphicVertexCollection[T <: PolymorphicDocumentOption]
                                    (graph: Graph, name: String, val types: List[PolymorphicType[T]])
                                    extends VertexCollection[T](graph, name) {
  private lazy val typeMap: Map[String, PolymorphicType[T]] = types.map(t => t.value -> t).toMap
  override implicit val encoder: Encoder[T] = new Encoder[T] {
    override def apply(a: T): Json = typeMap(a._type).encoder(a)
  }
  override implicit val decoder: Decoder[T] = new Decoder[T] {
    override def apply(c: HCursor): Result[T] = {
      val decoder = for {
        t <- Decoder[String].prepare(_.downField("_type"))
        d <- typeMap.get(t).fold(
          Decoder.failedWithMessage[T]("_type not found in polymorphic document")
        )(_.decoder)
      } yield d
      decoder(c)
    }
  }

  override protected def updateDocument(document: T, info: CreateInfo): T = typeMap(document._type).updateDocument(document, info)
}

trait PolymorphicDocumentOption extends DocumentOption {
  def _type: String
}

trait PolymorphicType[T] {
  def value: String
  def encoder: Encoder[T]
  def decoder: Decoder[T]
  def updateDocument(document: T, info: CreateInfo): T
} 
开发者ID:outr,项目名称:scarango,代码行数:42,代码来源:PolymorphicVertexCollection.scala


示例18: ArangoDB

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

import com.outr.arango.rest.{ArangoUser, CreateDatabaseRequest, Result}
import io.circe.{Decoder, Encoder}
import io.circe.generic.auto._
import io.youi.http.{HttpRequest, HttpResponse, Method}

import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global

class ArangoDB(val session: ArangoSession, val db: String) {
  protected[arango] def restful[Request, Response](name: String,
                                                   request: Request,
                                                   params: Map[String, String] = Map.empty,
                                                   errorHandler: Option[(HttpRequest, HttpResponse) => Response] = None,
                                                   method: Method = Method.Post)
                                                  (implicit encoder: Encoder[Request], decoder: Decoder[Response]): Future[Response] = {
    session.restful[Request, Response](Some(db), name, request, params, errorHandler, method)
  }

  protected[arango] def call[Response](name: String,
                                       method: Method,
                                       params: Map[String, String] = Map.empty,
                                       errorHandler: Option[(HttpRequest, HttpResponse) => Response] = None)
                                      (implicit decoder: Decoder[Response]): Future[Response] = {
    session.call[Response](Some(db), name, method, params, errorHandler)
  }

  def create(users: ArangoUser*): Future[Result[Boolean]] = {
    val request = CreateDatabaseRequest(db, users.toList)
    session.restful[CreateDatabaseRequest, Result[Boolean]](None, "database", request)
  }

  def drop(): Future[Result[Boolean]] = {
    session.call[Result[Boolean]](None, s"database/$db", Method.Delete)
  }

  def collection(name: String): ArangoCollection = new ArangoCollection(this, name)

  lazy val cursor: ArangoCursor = new ArangoCursor(this)
  lazy val replication: ArangoReplication = new ArangoReplication(this)

  
  def execute(query: Query): Future[Boolean] = {
    cursor[Unit](query, count = true).map { response =>
      assert(response.count.contains(0), s"Response count was not zero: ${response.count}.")
      !response.error
    }
  }

  lazy val graph: ArangoGraphs = new ArangoGraphs(this)
} 
开发者ID:outr,项目名称:scarango,代码行数:53,代码来源:ArangoDB.scala


示例19: circe

//设置package包名称以及导入依赖的类
package org.mdoc.common.model

import cats.data.Xor
import io.circe.{ Decoder, DecodingFailure, Encoder }
import scodec.bits.ByteVector

object circe {

  implicit val byteVectorDecoder: Decoder[ByteVector] =
    Decoder.instance { cursor =>
      Decoder[String].apply(cursor).flatMap { str =>
        ByteVector.fromBase64Descriptive(str) match {
          case Right(bytes) => Xor.right(bytes)
          case Left(err) => Xor.left(DecodingFailure(err, cursor.history))
        }
      }
    }

  implicit val byteVectorEncoder: Encoder[ByteVector] =
    Encoder[String].contramap(_.toBase64)
} 
开发者ID:m-doc,项目名称:common-model,代码行数:22,代码来源:circe.scala


示例20: CirceSpec

//设置package包名称以及导入依赖的类
package org.mdoc.common.model

import cats.data.Xor
import io.circe.{ Decoder, Encoder, Json }
import org.mdoc.common.model.circe._
import org.scalacheck.Prop._
import org.scalacheck.Properties
import scodec.bits.ByteVector

object CirceSpec extends Properties("circe") {

  property("Decoder[ByteVector] success") = secure {
    Decoder[ByteVector].decodeJson(Json.string("SGVsbG8=")) ?=
      Xor.right(ByteVector("Hello".getBytes))
  }

  property("Decoder[ByteVector] failure") = secure {
    Decoder[ByteVector].decodeJson(Json.string("???")).isLeft
  }

  property("Encoder[ByteVector]") = secure {
    Encoder[ByteVector].apply(ByteVector("Hello".getBytes)) ?=
      Json.string("SGVsbG8=")
  }
} 
开发者ID:m-doc,项目名称:common-model,代码行数:26,代码来源:CirceSpec.scala



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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