本文整理汇总了Scala中com.fasterxml.jackson.databind.JsonMappingException类的典型用法代码示例。如果您正苦于以下问题:Scala JsonMappingException类的具体用法?Scala JsonMappingException怎么用?Scala JsonMappingException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JsonMappingException类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: materializer
//设置package包名称以及导入依赖的类
package uk.gov.hmrc.agentinvitations.support
import akka.stream.ActorMaterializer
import com.fasterxml.jackson.databind.JsonMappingException
import org.scalatest.matchers.{MatchResult, Matcher}
import play.api.mvc.Result
import uk.gov.hmrc.play.http.HttpResponse
import uk.gov.hmrc.play.test.UnitSpec
import scala.util.Try
trait ErrorResultMatchers { this: UnitSpec =>
implicit def materializer: ActorMaterializer
class ErrorResultMatcher(expectedResult: Result) extends Matcher[HttpResponse] {
override def apply(left: HttpResponse): MatchResult = {
val expectedBodyJson = jsonBodyOf(expectedResult)
val rawNegatedFailureMessage =
s"""Response had expected status ${expectedResult.header.status} and body "$expectedBodyJson""""
if (left.status != expectedResult.header.status) {
MatchResult(
false,
s"""Response had status ${left.status} not expected status ${expectedResult.header.status}""",
rawNegatedFailureMessage
)
} else {
Try(left.json)
.map(json =>
MatchResult(
json == expectedBodyJson,
s"""Response had body "$json" not expected body "$expectedBodyJson""",
rawNegatedFailureMessage))
.recover {
case e: JsonMappingException =>
MatchResult(
false,
s"""Response had body "${left.body}" which did not parse as JSON due to exception:\n$e""",
rawNegatedFailureMessage)
}.get
}
}
}
def matchErrorResult(expectedResult: Result) = new ErrorResultMatcher(expectedResult)
}
开发者ID:hmrc,项目名称:agent-invitations,代码行数:49,代码来源:ErrorResultMatchers.scala
示例2: ServersetsTest
//设置package包名称以及导入依赖的类
package io.buoyant.namer.serversets
import com.fasterxml.jackson.databind.JsonMappingException
import com.twitter.finagle.util.LoadService
import io.buoyant.config.Parser
import io.buoyant.namer.{NamerConfig, NamerInitializer}
import io.buoyant.test.Exceptions
import org.scalatest.FunSuite
class ServersetsTest extends FunSuite with Exceptions {
def parse(yaml: String): ServersetsConfig = {
val mapper = Parser.objectMapper(yaml, Iterable(Seq(ServersetsInitializer)))
mapper.readValue[NamerConfig](yaml).asInstanceOf[ServersetsConfig]
}
test("zkHost list") {
val yaml = """
kind: io.l5d.serversets
zkAddrs:
- host: foo
port: 2181
- host: bar
port: 2182
"""
assert(parse(yaml).connectString == "foo:2181,bar:2182")
}
test("single zkHost") {
val yaml = """
kind: io.l5d.serversets
zkAddrs:
- host: foo
port: 2181
"""
assert(parse(yaml).connectString == "foo:2181")
}
test("missing hostname") {
val yaml = """
kind: io.l5d.serversets
zkAddrs:
- port: 2181
"""
assertThrows[JsonMappingException](parse(yaml))
}
test("default port") {
val yaml = """
kind: io.l5d.serversets
zkAddrs:
- host: foo
"""
assert(parse(yaml).connectString == "foo:2181")
}
test("service registration") {
assert(LoadService[NamerInitializer]().exists(_.isInstanceOf[ServersetsInitializer]))
}
}
开发者ID:linkerd,项目名称:linkerd,代码行数:62,代码来源:ServersetsTest.scala
示例3: ObjectWordSpec
//设置package包名称以及导入依赖的类
package pl.writeonly.son2.jack.providers
import com.fasterxml.jackson.core.JsonParseException
import com.fasterxml.jackson.databind.JsonMappingException
import pl.writeonly.son2.core.liners.{Liner, LinerOpt}
import pl.writeonly.son2.core.providers.Provider
import pl.writeonly.son2.jack.chain.ChainNotationPairJack
import pl.writeonly.son2.jack.core.Formats
import pl.writeonly.son2.spec.WhiteResultSpec
class ObjectWordSpec extends WhiteResultSpec {
val provider: Provider = ChainNotationPairJack(Formats.OBJECT)
"A Provider" should {
"produce JsonParseException when convert a" in {
assertThrows[JsonParseException] {
provider.convert("a")
}
}
"produce JsonMappingException when convert empty string" in {
assertThrows[JsonMappingException] {
provider.convert("")
}
}
}
val liner: Liner = new LinerOpt(provider)
"A Liner" should {
"return empty comment" in {
assertResult(provider.comment("") + "\n")(liner.apply(""))
}
}
}
开发者ID:writeonly,项目名称:son2,代码行数:34,代码来源:ObjectWordSpec.scala
示例4: JavaPropsWordSpec
//设置package包名称以及导入依赖的类
package pl.writeonly.son2.jack.providers
import com.fasterxml.jackson.core.JsonParseException
import com.fasterxml.jackson.databind.JsonMappingException
import pl.writeonly.son2.core.liners.{Liner, LinerOpt}
import pl.writeonly.son2.core.providers.Provider
import pl.writeonly.son2.jack.chain.ChainNotationPairJack
import pl.writeonly.son2.jack.core.Formats
import pl.writeonly.son2.spec.WhiteResultSpec
class JavaPropsWordSpec extends WhiteResultSpec {
val provider: Provider = ChainNotationPairJack(Formats.JAVA_PROPS)
"A Provider" should {
"produce JsonParseException when convert a" in {
assertThrows[JsonParseException] {
provider.convert("a")
}
}
"produce JsonMappingException when convert empty string" in {
assertThrows[JsonMappingException] {
provider.convert("")
}
}
}
val liner: Liner = new LinerOpt(provider)
"A Liner" should {
"return empty comment" in {
assertResult(provider.comment("") + "\n")(liner.apply(""))
}
}
}
开发者ID:writeonly,项目名称:son2,代码行数:34,代码来源:JavaPropsWordSpec.scala
示例5: XmlWordSpec
//设置package包名称以及导入依赖的类
package pl.writeonly.son2.jack.providers
import com.fasterxml.jackson.core.JsonParseException
import com.fasterxml.jackson.databind.JsonMappingException
import pl.writeonly.son2.core.liners.{Liner, LinerOpt}
import pl.writeonly.son2.core.providers.Provider
import pl.writeonly.son2.jack.chain.ChainNotationPairJack
import pl.writeonly.son2.jack.core.Formats
import pl.writeonly.son2.spec.WhiteResultSpec
class XmlWordSpec extends WhiteResultSpec {
val provider: Provider = ChainNotationPairJack(Formats.XML)
"A Provider" should {
"produce JsonParseException when convert a" in {
assertThrows[JsonParseException] {
provider.convert("a")
}
}
"produce JsonMappingException when convert empty string" in {
assertThrows[JsonMappingException] {
provider.convert("")
}
}
"produce JsonMappingException when convert []" in {
assertThrows[JsonMappingException] {
provider.convert("[]")
}
}
"produce JsonMappingException when convert [0,1]" in {
assertThrows[JsonMappingException] {
provider.convert("[0,1]")
}
}
}
val liner: Liner = new LinerOpt(provider)
"A Liner" should {
"return empty comment" in {
assertResult(provider.comment("") + "\n")(liner.apply(""))
}
}
}
开发者ID:writeonly,项目名称:son2,代码行数:44,代码来源:XmlWordSpec.scala
示例6: YamlWordSpec
//设置package包名称以及导入依赖的类
package pl.writeonly.son2.jack.providers
import com.fasterxml.jackson.core.JsonParseException
import com.fasterxml.jackson.databind.JsonMappingException
import pl.writeonly.son2.core.liners.{Liner, LinerOpt}
import pl.writeonly.son2.core.providers.Provider
import pl.writeonly.son2.jack.chain.ChainNotationPairJack
import pl.writeonly.son2.jack.core.Formats
import pl.writeonly.son2.spec.WhiteResultSpec
class YamlWordSpec extends WhiteResultSpec {
val provider: Provider = ChainNotationPairJack(Formats.YAML)
"A Provider" should {
"produce JsonParseException when convert a" in {
assertThrows[JsonParseException] {
provider.convert("a")
}
}
"produce JsonMappingException when convert empty string" in {
assertThrows[JsonMappingException] {
provider.convert("")
}
}
}
val liner: Liner = new LinerOpt(provider)
"A Liner" should {
"return empty comment" in {
assertResult(provider.comment("") + "\n")(liner.apply(""))
}
}
}
开发者ID:writeonly,项目名称:son2,代码行数:34,代码来源:YamlWordSpec.scala
示例7: CsvWordSpec
//设置package包名称以及导入依赖的类
package pl.writeonly.son2.jack.providers
import com.fasterxml.jackson.core.JsonParseException
import com.fasterxml.jackson.databind.JsonMappingException
import pl.writeonly.son2.core.liners.{Liner, LinerOpt}
import pl.writeonly.son2.core.providers.Provider
import pl.writeonly.son2.jack.chain.ChainNotationPairJack
import pl.writeonly.son2.jack.core.Formats
import pl.writeonly.son2.spec.WhiteResultSpec
class CsvWordSpec extends WhiteResultSpec {
val provider: Provider = ChainNotationPairJack(Formats.CSV)
"A Provider" should {
"produce JsonParseException when convert a" in {
assertThrows[JsonParseException] {
provider.convert("a")
}
}
"produce JsonMappingException when convert empty string" in {
assertThrows[JsonMappingException] {
provider.convert("")
}
}
}
val liner: Liner = new LinerOpt(provider)
"A Liner" should {
"return empty comment" in {
assertResult(provider.comment("") + "\n")(liner.apply(""))
}
}
}
开发者ID:writeonly,项目名称:son2,代码行数:34,代码来源:CsvWordSpec.scala
示例8: JsonMappingExceptionMapper
//设置package包名称以及导入依赖的类
package cronus.exception
import com.twitter.finagle.http.{Request, Response}
import com.twitter.finatra.http.exceptions.ExceptionMapper
import com.twitter.finatra.http.response.ResponseBuilder
import com.twitter.finatra.json.internal.caseclass.jackson.JacksonUtils
import com.twitter.inject.Logging
import javax.inject.{Inject, Singleton}
import com.fasterxml.jackson.databind.JsonMappingException
@Singleton
class JsonMappingExceptionMapper @Inject()(response: ResponseBuilder)
extends ExceptionMapper[JsonMappingException]
with Logging {
override def toResponse(request: Request, e: JsonMappingException): Response = {
warn(e)
response
.badRequest
.jsonError(JacksonUtils.errorMessage(e))
}
}
开发者ID:codeape,项目名称:cronus,代码行数:24,代码来源:JsonMappingExceptionMapper.scala
注:本文中的com.fasterxml.jackson.databind.JsonMappingException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论