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


Scala DeserializationException类代码示例

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


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


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