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

Scala DeserializationException类代码示例

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

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



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

示例1: SendTweet

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

import scala.collection.mutable.ArrayBuffer

import spray.json.DefaultJsonProtocol
import spray.json.DeserializationException
import spray.json.JsArray
import spray.json.JsNumber
import spray.json.JsObject
import spray.json.JsString
import spray.json.JsValue
import spray.json.JsonFormat
import spray.json.pimpAny

trait JsonFormats extends DefaultJsonProtocol {
  case class SendTweet(userId: Int, time: Long, msg: String)
  case class UserProfile(id: Int, name: String, statusCount: Int, favoritesCount: Int, followersCount: Int, followingCount: Int)
  case class SendMsg(senderId: Int, time: Long, msg: String, recepientId: Int)

  implicit val tweetFormat = jsonFormat3(SendTweet)
  implicit val userProfileFormat = jsonFormat6(UserProfile)
  implicit val reTweetFormat = jsonFormat4(SendMsg)

  implicit object TimelineJsonFormat extends JsonFormat[Project4Server.Tweets] {
    def write(c: Project4Server.Tweets) = JsObject(
      "authorId" -> JsNumber(c.authorId),
      "message" -> JsString(c.message),
      "timeStamp" -> JsString(c.timeStamp.toString),
      "tweetId" -> JsString(c.tweetId),
      "mentions" -> JsArray(c.mentions.map(_.toJson).toVector),
      "hashTags" -> JsArray(c.hashtags.map(_.toJson).toVector))
    def read(value: JsValue) = {
      value.asJsObject.getFields("tweetId", "authorId", "message", "timeStamp", "mentions", "hashTags") match {
        case Seq(JsString(tweetId), JsNumber(authorId), JsString(message), JsString(timeStamp), JsArray(mentions), JsArray(hashTags)) =>
          new Project4Server.Tweets(tweetId, authorId.toInt, message, timeStamp.toLong, mentions.map(_.convertTo[String]).to[ArrayBuffer], hashTags.map(_.convertTo[String]).to[ArrayBuffer])
        case _ => throw new DeserializationException("Tweets expected")
      }
    }
  }

  implicit object MessagesJsonFormat extends JsonFormat[Project4Server.Messages] {
    def write(c: Project4Server.Messages) = JsObject(
      "authorId" -> JsNumber(c.authorId),
      "message" -> JsString(c.message),
      "timeStamp" -> JsString(c.timeStamp.toString),
      "tweetId" -> JsString(c.tweetId),
      "mentions" -> JsArray(c.mentions.map(_.toJson).toVector),
      "hashTags" -> JsArray(c.hashtags.map(_.toJson).toVector),
      "recepientId" -> JsNumber(c.recepientId))
    def read(value: JsValue) = {
      value.asJsObject.getFields("tweetId", "authorId", "message", "timeStamp", "mentions", "hashTags", "recepientId") match {
        case Seq(JsString(tweetId), JsNumber(authorId), JsString(message), JsString(timeStamp), JsArray(mentions), JsArray(hashTags), JsNumber(recepientId)) =>
          new Project4Server.Messages(recepientId.toInt, tweetId, authorId.toInt, message, timeStamp.toLong, mentions.map(_.convertTo[String]).to[ArrayBuffer], hashTags.map(_.convertTo[String]).to[ArrayBuffer])
        case _ => throw new DeserializationException("Tweets expected")
      }
    }
  }
} 
开发者ID:abhinavrungta,项目名称:MineBitcoin,代码行数:59,代码来源:Formats.scala


示例2: DateJsonFormat

//设置package包名称以及导入依赖的类
package com.durooma.api.route

import java.sql.Date

import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport
import com.durooma.api.model._
import com.durooma.db.Tables
import org.joda.time.DateTime
import org.joda.time.format.{DateTimeFormatter, ISODateTimeFormat}
import spray.json.{DefaultJsonProtocol, DeserializationException, JsString, JsValue, RootJsonFormat}


trait JsonSupport extends SprayJsonSupport with DefaultJsonProtocol {

  implicit object DateJsonFormat extends RootJsonFormat[DateTime] {

    private val parserISO : DateTimeFormatter = ISODateTimeFormat.dateTimeNoMillis()

    override def write(obj: DateTime) = JsString(parserISO.print(obj))

    override def read(json: JsValue) : DateTime = json match {
      case JsString(s) => parserISO.parseDateTime(s)
      case _ => throw DeserializationException("Invalid date format: " + json)
    }
  }

  implicit object SqlDateJsonFormat extends RootJsonFormat[Date] {

    override def write(obj: Date) = JsString(obj.toString)
    override def read(json: JsValue) = json match {
      case JsString(s) => Date.valueOf(s)
      case _ => throw DeserializationException("Invalid date format: " + json)
    }

  }

  implicit val userFormat = jsonFormat5(User.apply)
  implicit val userRegistrationFormat = jsonFormat5(UserRegistration.apply)
  implicit val accountFormat = jsonFormat4(Account.apply)
  implicit val accounBodyFormat = jsonFormat2(AccountBody.apply)
  implicit val labelFormat = jsonFormat3(Tables.LabelRow.apply)
  implicit val transactionFormat = jsonFormat8(Transaction.apply)
  implicit val transactionBodyFormat = jsonFormat7(TransactionBody.apply)
  implicit val sessionFormat = jsonFormat3(Session.apply)
  implicit val credentialsFormat = jsonFormat2(CustomCredentials.apply)

} 
开发者ID:durooma,项目名称:api,代码行数:48,代码来源:JsonSupport.scala


示例3: CoordinateFormat

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

import akka.http.scaladsl.unmarshalling.Unmarshaller
import base.CaseObjectSerializationSupport
import mapdomain.graph.Coordinate
import mapdomain.sidewalk.Ramp
import spray.json.{ DefaultJsonProtocol, DeserializationException, JsNumber, JsObject, JsString, JsValue, RootJsonFormat }

trait ModelFormatter extends DefaultJsonProtocol with CaseObjectSerializationSupport {

  implicit object CoordinateFormat extends RootJsonFormat[Coordinate] {
    def write(c: Coordinate) = JsObject(
      "lat" -> JsNumber(c.latitude),
      "lng" -> JsNumber(c.longitude))

    def read(value: JsValue) = value.asJsObject.getFields("lat", "lng") match {
      case Seq(JsNumber(latitude), JsNumber(longitude)) ?
        Coordinate(latitude.toDouble, longitude.toDouble)
      case _ ? throw DeserializationException("Coordinate expected")
    }
  }

  implicit object PathCoordinateFormat extends RootJsonFormat[PathCoordinate] {
    def write(pc: PathCoordinate) =
      if (pc.street.isDefined)
        JsObject(
          "lat" -> JsNumber(pc.coordinate.latitude),
          "lng" -> JsNumber(pc.coordinate.longitude),
          "street" -> JsString(pc.street.get))
      else
        JsObject(
          "lat" -> JsNumber(pc.coordinate.latitude),
          "lng" -> JsNumber(pc.coordinate.longitude))

    def read(value: JsValue) = value.asJsObject.getFields("lat", "lng", "street") match {
      case Seq(JsNumber(latitude), JsNumber(longitude), JsString(street)) ?
        PathCoordinate(Coordinate(latitude.toDouble, longitude.toDouble), Some(street))
      case Seq(JsNumber(latitude), JsNumber(longitude)) ?
        PathCoordinate(Coordinate(latitude.toDouble, longitude.toDouble))
      case _ ? throw DeserializationException("PathCoordinate expected")
    }
  }

  implicit val EdgeTypeFormat = caseObjectJsonFormat[EdgeType](StreetEdgeType, SidewalkEdgeType, StreetCrossingEdgeType)
  implicit val VertexTypeFormat = caseObjectJsonFormat[VertexType](StreetVertexType, SidewalkVertexType)
  implicit val ReportableElementTypeFormat = caseObjectJsonFormat[ReportableElementType](RAMP, SIDEWALK)
  implicit val RampFormat = jsonFormat4(Ramp.apply)
  implicit val EdgeFormat = jsonFormat4(Edge.apply)
  implicit val VertexFormat = jsonFormat3(Vertex.apply)
  implicit val MapContainerFormat = jsonFormat2(MapContainer.apply)
  implicit val StreetFormat = jsonFormat3(Street.apply)
  implicit val SidewalkFormat = jsonFormat2(Sidewalk.apply)
  implicit val ReportableElementFormat = jsonFormat6(ReportableElement.apply)
  implicit val StopFormat = jsonFormat4(Stop.apply)
  implicit val PublicTransportPathFormat = jsonFormat4(PublicTransportPath)
  implicit val StopCombinationFormat = jsonFormat6(PTCombination.apply)

  implicit val EdgeTypeUnmarshaller = Unmarshaller.strict[String, EdgeType](EdgeTypeFormat.mapping)
} 
开发者ID:cspinetta,项目名称:footpath-routing,代码行数:60,代码来源:ModelFormatter.scala


示例4: serviceSuccessJsonFormat

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

import common.{ErrorMessage, ServiceSuccess}
import spray.json.{DefaultJsonProtocol, DeserializationException, JsBoolean, JsFalse, JsObject, JsString, JsTrue, JsValue, JsonFormat, RootJsonFormat}

trait CommonJsonProtocol {
  this: DefaultJsonProtocol =>

  implicit def serviceSuccessJsonFormat[A](implicit format: JsonFormat[A]) = new RootJsonFormat[ServiceSuccess[A]] {

    override def write(value: ServiceSuccess[A]): JsValue = {
      JsObject("ok" -> JsBoolean(true), "result" -> format.write(value.result))
    }

    override def read(json: JsValue): ServiceSuccess[A] = {
      val root = json.asJsObject
      (root.fields.get("ok"), root.fields.get("result")) match {
        case (Some(JsTrue), Some(jsValue)) => ServiceSuccess(format.read(jsValue))

        case _ => throw new DeserializationException("JSON not a ServiceSuccess")
      }
    }
  }

  implicit object errorMessageJsonFormat extends RootJsonFormat[ErrorMessage] {

    override def write(value: ErrorMessage): JsValue = {
      JsObject("ok" -> JsBoolean(false), "error" -> JsString(value.text))
    }

    override def read(json: JsValue): ErrorMessage = {
      val root = json.asJsObject
      (root.fields.get("ok"), root.fields.get("error")) match {
        case (Some(JsFalse), Some(JsString(errorText))) => new ErrorMessage {
          val text = errorText
        }

        case _ => throw new DeserializationException("JSON not a ErrorMessage")
      }
    }
  }


  implicit def rootEitherFormat[A : RootJsonFormat, B : RootJsonFormat] = new RootJsonFormat[Either[A, B]] {
    val format = DefaultJsonProtocol.eitherFormat[A, B]

    def write(either: Either[A, B]) = format.write(either)

    def read(value: JsValue) = format.read(value)
  }
} 
开发者ID:Lastik,项目名称:money-transfer-sample,代码行数:52,代码来源:CommonJsonProtocol.scala


示例5: ModelEntityKeyJsonFormat

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

import core.model.ModelEntityKey
import spray.json.{DeserializationException, JsString, JsValue, RootJsonFormat}

package object json {

  class ModelEntityKeyJsonFormat[T <: ModelEntityKey : Manifest] extends RootJsonFormat[T] {
    def write(obj: T): JsValue = JsString(obj.id.toString)

    def read(json: JsValue): T = json match {
      case JsString(str) =>
        manifest.runtimeClass.getConstructors()(0).newInstance(str).asInstanceOf[T]
      case _ => throw new DeserializationException("ModelEntityKeyJsonFormat:read method: JsString expected")
    }
  }

} 
开发者ID:Lastik,项目名称:money-transfer-sample,代码行数:19,代码来源:package.scala


示例6: write

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

import core.model.{Account, AccountId}
import core.services.{AccountDTO, AccountsDTO}
import spray.json.{DefaultJsonProtocol, DeserializationException, JsString, JsValue, JsonFormat}
import squants.market.Money

trait AccountJsonProtocol {
  this: DefaultJsonProtocol with CustomerJsonProtocol with CommonJsonProtocol =>

  implicit val accountIdJsonFormat = new ModelEntityKeyJsonFormat[AccountId]

  implicit val moneyJsonFormat = new JsonFormat[Money] {
    def write(obj: Money): JsValue =
      JsString(obj.toString())

    def read(json: JsValue): Money = {
      json match {
        case JsString(str) =>
          Money.apply(str).getOrElse(throw new DeserializationException("Failed to deserialize Money"))
        case _ => throw new DeserializationException("Failed to deserialize Money")
      }
    }
  }

  import Account._

  implicit val accountJsonFormat = jsonFormat(Account.apply, "id", "customerId", "balance")

  implicit val accountDTOJsonFormat = jsonFormat2(AccountDTO.apply)

  implicit val accountsDTOJsonFormat = jsonFormat1(AccountsDTO.apply)
} 
开发者ID:Lastik,项目名称:money-transfer-sample,代码行数:34,代码来源:AccountJsonProtocol.scala


示例7: VizRecJsonProtocol

//设置package包名称以及导入依赖的类
package com.lavsurgut.vizr.specs.vizrec

import spray.json.{DefaultJsonProtocol, DeserializationException, JsArray, JsObject, JsString, JsValue, JsonFormat, RootJsonFormat, _}

object VizRecJsonProtocol extends DefaultJsonProtocol {
  implicit object FieldFormat extends JsonFormat[Field] {
    def write(c: Field) =

        JsObject(
        Seq(
          Some("channel" -> c.channel.toString.toJson),
          Some("type" -> c.`type`.toString.toJson),
          c.aggregate.map(aggregate => "aggregate" -> aggregate.toString.toJson),
          c.field.map(field => "field" -> field.toJson),
          c.timeUnit.map(timeUnit => "timeUnit" -> timeUnit.toString.toJson)
        ).flatten: _*
    )

    def read(value: JsValue) = {
      value.asJsObject.getFields("channel", "type") match {
        case Seq(JsString(channel), JsString(ttype)) =>
          new Field(
            channel = Channel.withName(channel),
            `type` = Type.withName(ttype),
            aggregate = value.asJsObject.fields.get("aggregate").map(v => Aggregate.withName(v.convertTo[String])),
            field = value.asJsObject.fields.get("field").map(v => v.convertTo[String]),
            timeUnit = value.asJsObject.fields.get("timeUnit").map(v => TimeUnit.withName(v.convertTo[String]))
          )
        case _ => throw new DeserializationException("Field spec expected")
      }
    }
  }

  implicit object VizRecSpecFormat extends RootJsonFormat[VizRecSpec] {
    def write(c: VizRecSpec) = JsObject(
      "mark" -> JsString(c.mark.toString),
      "fields" -> JsArray(c.fields.map(f => FieldFormat.write(f)).toVector)
    )
    def read(value: JsValue) = {
      value.asJsObject.getFields("mark", "fields") match {
        case Seq(JsString(mark), JsArray(fields)) =>
          new VizRecSpec(Mark.withName(mark), fields.map(f => FieldFormat.read(f)).toSeq)
        case _ => throw new DeserializationException("VizRec spec expected")
      }
    }
  }


} 
开发者ID:lavsurgut,项目名称:vizr,代码行数:50,代码来源:VizRecJsonProtocol.scala


示例8: StandardJsonProtocol

//设置package包名称以及导入依赖的类
package io.clouderite.commons.scala.berries.json

import java.nio.file.{Path, Paths}
import java.time.Instant

import spray.json.{DeserializationException, JsFalse, JsNumber, JsString, JsTrue, JsValue, RootJsonFormat}

object StandardJsonProtocol {
  implicit val instantJson = InstantJsonFormat
  implicit val pathJson = PathJsonFormat
  implicit val anyJson = PathJsonFormat
}

object InstantJsonFormat extends RootJsonFormat[Instant] {
  def write(obj: Instant): JsValue = JsNumber(obj.toEpochMilli)

  def read(json: JsValue): Instant = json match {
    case JsNumber(number) => Instant.ofEpochMilli(number.toLong)
    case _ => throw DeserializationException("JsNumber expected")
  }
}

object PathJsonFormat extends RootJsonFormat[Path] {
  def write(obj: Path): JsValue = JsString(obj.toString)

  def read(json: JsValue): Path = json match {
    case JsString(str) => Paths.get(str)
    case _ => throw DeserializationException("JsString expected")
  }
}

object AnyJsonFormat extends RootJsonFormat[Any] {
  def write(x: Any): JsValue = x match {
    case n: Int => JsNumber(n)
    case n: Long => JsNumber(n)
    case n: Double => JsNumber(n)
    case n: BigDecimal => JsNumber(n)
    case s: String => JsString(s)
    case b: Boolean if b => JsTrue
    case b: Boolean if !b => JsFalse
  }
  
  def read(value: JsValue): Any = value match {
    case JsNumber(n) => n.doubleValue
    case JsString(s) => s
    case JsTrue => true
    case JsFalse => false
  }
} 
开发者ID:clouderite,项目名称:scala-berries,代码行数:50,代码来源:StandardJsonProtocol.scala


示例9: SubmissionStatusJsonFormat

//设置package包名称以及导入依赖的类
package hmda.api.protocol.processing

import hmda.model.fi._
import hmda.api.model.institutions.submissions.{ ContactSummary, FileSummary, RespondentSummary, SubmissionSummary }
import hmda.api.model.{ Receipt, Submissions }
import hmda.api.protocol.validation.ValidationResultProtocol
import spray.json.{ DeserializationException, JsNumber, JsObject, JsString, JsValue, RootJsonFormat }

trait SubmissionProtocol extends ValidationResultProtocol {

  implicit object SubmissionStatusJsonFormat extends RootJsonFormat[SubmissionStatus] {
    override def write(status: SubmissionStatus): JsValue = {
      JsObject(
        "code" -> JsNumber(status.code),
        "message" -> JsString(status.message),
        "description" -> JsString(status.description)
      )
    }

    override def read(json: JsValue): SubmissionStatus = {
      json.asJsObject.getFields("code").head match {
        case JsNumber(s) => s.toInt match {
          case 1 => Created
          case 2 => Uploading
          case 3 => Uploaded
          case 4 => Parsing
          case 5 => ParsedWithErrors
          case 6 => Parsed
          case 7 => Validating
          case 8 => ValidatedWithErrors
          case 9 => Validated
          case 10 => Signed
          case -1 =>
            val message = json.asJsObject.getFields("message").head.toString()
            Failed(message.substring(1, message.length - 1))
          case _ => throw DeserializationException("Submission Status expected")
        }
        case _ => throw DeserializationException("Unable to deserialize")

      }
    }
  }

  implicit val submissionIdProtocol = jsonFormat3(SubmissionId.apply)
  implicit val submissionFormat = jsonFormat5(Submission.apply)
  implicit val submissionsFormat = jsonFormat1(Submissions.apply)
  implicit val receiptFormat = jsonFormat3(Receipt.apply)

  implicit val fileSummaryFormat = jsonFormat3(FileSummary.apply)
  implicit val contactSummaryFormat = jsonFormat3(ContactSummary.apply)
  implicit val respondentSummaryFormat = jsonFormat5(RespondentSummary.apply)
  implicit val submissionSummaryFormat = jsonFormat2(SubmissionSummary.apply)
} 
开发者ID:cfpb,项目名称:hmda-platform,代码行数:54,代码来源:SubmissionProtocol.scala


示例10: FilingStatusJsonFormat

//设置package包名称以及导入依赖的类
package hmda.api.protocol.processing

import hmda.api.model.{ FilingDetail, Filings }
import hmda.model.fi._
import spray.json.{ DefaultJsonProtocol, DeserializationException, JsNumber, JsObject, JsString, JsValue, RootJsonFormat }

trait FilingProtocol extends DefaultJsonProtocol with SubmissionProtocol {
  implicit object FilingStatusJsonFormat extends RootJsonFormat[FilingStatus] {
    override def read(json: JsValue): FilingStatus = {
      json.asJsObject.getFields("message").head match {
        case JsString(s) => s match {
          case "not-started" => NotStarted
          case "in-progress" => InProgress
          case "completed" => Completed
          case "cancelled" => Cancelled
        }
        case _ => throw new DeserializationException("Filing Status expected")
      }
    }

    override def write(status: FilingStatus): JsValue = {
      JsObject(
        "code" -> JsNumber(status.code),
        "message" -> JsString(status.message)
      )
    }
  }

  implicit val filingFormat = jsonFormat6(Filing.apply)
  implicit val filingsFormat = jsonFormat1(Filings.apply)
  implicit val filingDetailFormat = jsonFormat2(FilingDetail.apply)
} 
开发者ID:cfpb,项目名称:hmda-platform,代码行数:33,代码来源:FilingProtocol.scala


示例11: PathJsonFormat

//设置package包名称以及导入依赖的类
package hmda.api.protocol.processing

import akka.http.scaladsl.model.Uri.Path
import hmda.api.model.ErrorResponse
import spray.json.{ DefaultJsonProtocol, DeserializationException, JsString, JsValue, RootJsonFormat }

trait ApiErrorProtocol extends DefaultJsonProtocol {
  implicit object PathJsonFormat extends RootJsonFormat[Path] {
    override def write(path: Path): JsValue = JsString(path.toString)
    override def read(path: JsValue): Path =
      path match {
        case JsString(s) => Path(s)
        case _ => throw new DeserializationException("Unable to deserialize")
      }
  }

  implicit val apiErrorFormat = jsonFormat3(ErrorResponse.apply)

} 
开发者ID:cfpb,项目名称:hmda-platform,代码行数:20,代码来源:ApiErrorProtocol.scala


示例12: ValidationErrorTypeFormat

//设置package包名称以及导入依赖的类
package hmda.api.protocol.validation

import hmda.api.model.SingleValidationErrorResult
import hmda.model.validation._
import hmda.validation.engine._
import spray.json.{ DefaultJsonProtocol, DeserializationException, JsString, JsValue, RootJsonFormat }

trait ValidationResultProtocol extends DefaultJsonProtocol {
  implicit object ValidationErrorTypeFormat extends RootJsonFormat[ValidationErrorType] {
    override def read(json: JsValue): ValidationErrorType = {
      json match {
        case JsString(s) => s match {
          case "syntactical" => Syntactical
          case "validity" => Validity
          case "quality" => Quality
          case "macro" => Macro
        }
        case _ => throw DeserializationException("ValidationErrorType expected")
      }
    }
    override def write(errorType: ValidationErrorType): JsValue = {
      errorType match {
        case Syntactical => JsString("syntactical")
        case Validity => JsString("validity")
        case Quality => JsString("quality")
        case Macro => JsString("macro")
      }
    }
  }

  implicit object ValidationErrorFormat extends RootJsonFormat[ValidationError] {
    override def read(json: JsValue): ValidationError = json.asJsObject.fields.getOrElse("errorType", JsString("")) match {
      case JsString("syntactical") => syntacticalValidationErrorFormat.read(json)
      case JsString("validity") => validityValidationErrorFormat.read(json)
      case JsString("quality") => qualityValidationErrorFormat.read(json)
      case JsString("macro") => macroValidationErrorFormat.read(json)
      case _ => throw DeserializationException("ValidationError expected")
    }
    override def write(error: ValidationError): JsValue = error.errorType match {
      case Syntactical => syntacticalValidationErrorFormat.write(error.asInstanceOf[SyntacticalValidationError])
      case Validity => validityValidationErrorFormat.write(error.asInstanceOf[ValidityValidationError])
      case Quality => qualityValidationErrorFormat.write(error.asInstanceOf[QualityValidationError])
      case Macro => macroValidationErrorFormat.write(error.asInstanceOf[MacroValidationError])
    }
  }

  implicit val syntacticalValidationErrorFormat = jsonFormat3(SyntacticalValidationError.apply)
  implicit val validityValidationErrorFormat = jsonFormat3(ValidityValidationError.apply)
  implicit val qualityValidationErrorFormat = jsonFormat3(QualityValidationError.apply)
  implicit val macroValidationErrorFormat = jsonFormat1(MacroValidationError.apply)
  implicit val larValidationErrorsFormat = jsonFormat1(LarValidationErrors.apply)
  implicit val tsValidationErrorsFormat = jsonFormat1(TsValidationErrors.apply)
  implicit val validationErrorsSummaryFormat = jsonFormat1(ValidationErrorsSummary.apply)
  implicit val singleValidationResultFormat = jsonFormat3(SingleValidationErrorResult.apply)
} 
开发者ID:cfpb,项目名称:hmda-platform,代码行数:56,代码来源:ValidationResultProtocol.scala


示例13: CharacteristicFormat

//设置package包名称以及导入依赖的类
package hmda.publication.reports.protocol

import hmda.model.publication.reports.CharacteristicEnum
import spray.json.{ DefaultJsonProtocol, DeserializationException, JsString, JsValue, RootJsonFormat }

trait CharacteristicEnumProtocol extends DefaultJsonProtocol {

  implicit object CharacteristicFormat extends RootJsonFormat[CharacteristicEnum] {
    override def write(obj: CharacteristicEnum): JsValue = JsString(obj.entryName)

    override def read(json: JsValue): CharacteristicEnum = json match {
      case JsString(name) =>
        try {
          CharacteristicEnum.withName(name)
        } catch {
          case _: NoSuchElementException => throw DeserializationException(
            s"Unable to translate JSON string into valid ReportType value: $name"
          )
        }
      case _ => throw DeserializationException("Unable to deserialize")
    }
  }
} 
开发者ID:cfpb,项目名称:hmda-platform,代码行数:24,代码来源:CharacteristicEnumProtocol.scala


示例14: ReportTypeFormat

//设置package包名称以及导入依赖的类
package hmda.publication.reports.protocol

import hmda.model.publication.reports.ReportTypeEnum
import spray.json.{ DefaultJsonProtocol, DeserializationException, JsString, JsValue, RootJsonFormat }

trait ReportTypeEnumProtocol extends DefaultJsonProtocol {

  implicit object ReportTypeFormat extends RootJsonFormat[ReportTypeEnum] {

    override def write(obj: ReportTypeEnum): JsValue = JsString(obj.entryName)

    override def read(json: JsValue): ReportTypeEnum = json match {
      case JsString(name) =>
        try {
          ReportTypeEnum.withName(name)
        } catch {
          case _: NoSuchElementException => throw DeserializationException(
            s"Unable to translate JSON string into valid ReportType value: $name"
          )
        }
      case _ => throw DeserializationException("Unable to deserialize")
    }

  }
} 
开发者ID:cfpb,项目名称:hmda-platform,代码行数:26,代码来源:ReportTypeEnumProtocol.scala


示例15: EthnicityEnumFormat

//设置package包名称以及导入依赖的类
package hmda.publication.reports.protocol

import hmda.model.publication.reports.EthnicityEnum
import hmda.model.publication.reports.EthnicityEnum.{ HispanicOrLatino, Joint, NotAvailable, NotHispanicOrLatino }
import spray.json.{ DefaultJsonProtocol, DeserializationException, JsString, JsValue, RootJsonFormat }

trait EthnicityEnumProtocol extends DefaultJsonProtocol {

  implicit object EthnicityEnumFormat extends RootJsonFormat[EthnicityEnum] {

    override def write(obj: EthnicityEnum): JsValue = JsString(obj.description)

    override def read(json: JsValue): EthnicityEnum = json match {
      case JsString(description) => description match {
        case HispanicOrLatino.description => HispanicOrLatino
        case NotHispanicOrLatino.description => NotHispanicOrLatino
        case NotAvailable.description => NotAvailable
        case Joint.description => Joint
        case _ => throw DeserializationException(s"Unable to translate JSON string into valid Action Type value: $description")
      }
      case _ => throw DeserializationException("Unable to deserialize")
    }

  }
} 
开发者ID:cfpb,项目名称:hmda-platform,代码行数:26,代码来源:EthnicityEnumProtocol.scala


示例16: MinorityStatusEnumFormat

//设置package包名称以及导入依赖的类
package hmda.publication.reports.protocol

import hmda.model.publication.reports.MinorityStatusEnum
import hmda.model.publication.reports.MinorityStatusEnum.{ OtherIncludingHispanic, WhiteNonHispanic }
import spray.json.{ DefaultJsonProtocol, DeserializationException, JsString, JsValue, RootJsonFormat }

trait MinorityStatusEnumProtocol extends DefaultJsonProtocol {

  implicit object MinorityStatusEnumFormat extends RootJsonFormat[MinorityStatusEnum] {
    override def write(obj: MinorityStatusEnum): JsValue = JsString(obj.description)

    override def read(json: JsValue): MinorityStatusEnum = json match {
      case JsString(description) => description match {
        case WhiteNonHispanic.description => WhiteNonHispanic
        case OtherIncludingHispanic.description => OtherIncludingHispanic
        case _ => throw DeserializationException(s"Unable to translate JSON string into valid Action Type value: $description")
      }
      case _ => throw DeserializationException("Unable to deserialize")
    }
  }

} 
开发者ID:cfpb,项目名称:hmda-platform,代码行数:23,代码来源:MinorityStatusEnumProtocol.scala


示例17: RaceEnumFormat

//设置package包名称以及导入依赖的类
package hmda.publication.reports.protocol

import hmda.model.publication.reports.RaceEnum
import hmda.model.publication.reports.RaceEnum._
import spray.json.{ DefaultJsonProtocol, DeserializationException, JsString, JsValue, RootJsonFormat }

trait RaceEnumProtocol extends DefaultJsonProtocol {

  implicit object RaceEnumFormat extends RootJsonFormat[RaceEnum] {

    override def write(obj: RaceEnum): JsValue = JsString(obj.description)

    override def read(json: JsValue): RaceEnum = json match {
      case JsString(description) => description match {
        case AmericanIndianOrAlaskaNative.description => AmericanIndianOrAlaskaNative
        case Asian.description => Asian
        case BlackOrAfricanAmerican.description => BlackOrAfricanAmerican
        case HawaiianOrPacific.description => HawaiianOrPacific
        case White.description => White
        case NotProvided.description => NotProvided
        case TwoOrMoreMinority.description => TwoOrMoreMinority
        case Joint.description => Joint
        case _ => throw DeserializationException(s"Unable to translate JSON string into valid Action Type value: $description")
      }

      case _ => throw DeserializationException("Unable to deserialize")
    }

  }
} 
开发者ID:cfpb,项目名称:hmda-platform,代码行数:31,代码来源:RaceEnumProtocol.scala


示例18: ActionTakenTypeEnumFormat

//设置package包名称以及导入依赖的类
package hmda.publication.reports.protocol

import hmda.model.publication.reports.ActionTakenTypeEnum
import hmda.model.publication.reports.ActionTakenTypeEnum._
import spray.json.{ DefaultJsonProtocol, DeserializationException, JsString, JsValue, RootJsonFormat }

trait ActionTakenTypeEnumProtocol extends DefaultJsonProtocol {

  implicit object ActionTakenTypeEnumFormat extends RootJsonFormat[ActionTakenTypeEnum] {

    override def write(obj: ActionTakenTypeEnum): JsValue = JsString(obj.description)

    override def read(json: JsValue): ActionTakenTypeEnum = json match {
      case JsString(description) => description match {
        case ApplicationReceived.description => ApplicationReceived
        case LoansOriginated.description => LoansOriginated
        case ApprovedButNotAccepted.description => ApprovedButNotAccepted
        case ApplicationsDenied.description => ApplicationsDenied
        case ApplicationsWithdrawn.description => ApplicationsWithdrawn
        case ClosedForIncompleteness.description => ClosedForIncompleteness
        case LoanPurchased.description => LoanPurchased
        case PreapprovalDenied.description => PreapprovalDenied
        case PreapprovalApprovedButNotAccepted.description => PreapprovalApprovedButNotAccepted
        case _ => throw DeserializationException(s"Unable to translate JSON string into valid Action Type value: $description")
      }
      case _ => throw DeserializationException("Unable to deserialize")

    }

  }

} 
开发者ID:cfpb,项目名称:hmda-platform,代码行数:33,代码来源:ActionTakenTypeEnumProtocol.scala


示例19: ApplicantIncomeEnumFormat

//设置package包名称以及导入依赖的类
package hmda.publication.reports.protocol

import hmda.model.publication.reports.ApplicantIncomeEnum
import hmda.model.publication.reports.ApplicantIncomeEnum._
import spray.json.{ DefaultJsonProtocol, DeserializationException, JsString, JsValue, RootJsonFormat }

trait ApplicantIncomeEnumProtocol extends DefaultJsonProtocol {

  implicit object ApplicantIncomeEnumFormat extends RootJsonFormat[ApplicantIncomeEnum] {

    override def write(obj: ApplicantIncomeEnum): JsValue = JsString(obj.description)

    override def read(json: JsValue): ApplicantIncomeEnum = json match {
      case JsString(description) => description match {
        case LessThan50PercentOfMSAMedian.description => LessThan50PercentOfMSAMedian
        case Between50And79PercentOfMSAMedian.description => Between50And79PercentOfMSAMedian
        case Between80And99PercentOfMSAMedian.description => Between80And99PercentOfMSAMedian
        case Between100And119PercentOfMSAMedian.description => Between100And119PercentOfMSAMedian
        case GreaterThan120PercentOfMSAMedian.description => GreaterThan120PercentOfMSAMedian
        case _ => throw DeserializationException(s"Unable to translate JSON string into valid Action Type value: $description")
      }

      case _ => throw DeserializationException("Unable to deserialize")
    }

  }
} 
开发者ID:cfpb,项目名称:hmda-platform,代码行数:28,代码来源:ApplicantIncomeEnumProtocol.scala


示例20: AsyncInterface

//设置package包名称以及导入依赖的类
package io.hydrosphere.mist.master.interfaces.async

import io.hydrosphere.mist.jobs.JobDetails.Source
import io.hydrosphere.mist.master.MasterService
import io.hydrosphere.mist.master.interfaces.JsonCodecs
import io.hydrosphere.mist.master.models._
import io.hydrosphere.mist.utils.Logger
import spray.json.{DeserializationException, JsonParser, pimpString}
import JsonCodecs._

class AsyncInterface(
  masterService: MasterService,
  input: AsyncInput,
  source: Source
) extends Logger {

  def start(): this.type  = {
    input.start(process)
    this
  }

  private def process(message: String): Unit = {
    try {
      val json = message.parseJson
      val request = json.convertTo[AsyncJobStartRequest]
      masterService.runJob(request.toCommon, source)
    } catch {
      case e: DeserializationException =>
        logger.warn(s"Message $message does not conform with start request")
      case e: JsonParser.ParsingException =>
        logger.warn(s"Handled invalid message $message")
      case e: Throwable =>
        logger.error(s"Error occurred during handling message $message", e)
    }
  }

  def close(): Unit = input.close()

} 
开发者ID:Hydrospheredata,项目名称:mist,代码行数:40,代码来源:AsyncInterface.scala



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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