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

Scala Include类代码示例

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

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



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

示例1: GenericResponse

//设置package包名称以及导入依赖的类
package com.flipkart.connekt.commons.iomodels

import com.fasterxml.jackson.annotation.JsonInclude.Include
import com.fasterxml.jackson.annotation.JsonSubTypes.Type
import com.fasterxml.jackson.annotation.{JsonInclude, JsonSubTypes, JsonTypeInfo}

case class GenericResponse(status: Int, request: AnyRef, response: ResponseBody)

@JsonTypeInfo(
  use = JsonTypeInfo.Id.NAME,
  include = JsonTypeInfo.As.PROPERTY,
  property = "type"
)
@JsonSubTypes(Array(
  new Type(value = classOf[Response], name = "RESPONSE"),
  new Type(value = classOf[SendResponse], name = "SEND_RESPONSE")
))
abstract class ResponseBody

case class Response(@JsonInclude(Include.NON_NULL) message: String, data: Any) extends ResponseBody

case class SendResponse(@JsonInclude(Include.NON_NULL) message: String, success: Map[String, Set[String]], failure: List[String]) extends ResponseBody 
开发者ID:ayush03agarwal,项目名称:connekt,代码行数:23,代码来源:GenericResponse.scala


示例2: Mapper

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

import akka.http.scaladsl.marshalling.Marshaller.withFixedContentType
import akka.http.scaladsl.marshalling.ToEntityMarshaller
import akka.http.scaladsl.model.{ContentTypes, HttpEntity, HttpRequest}
import akka.http.scaladsl.unmarshalling.{FromRequestUnmarshaller, Unmarshal, Unmarshaller}
import akka.stream.Materializer
import com.fasterxml.jackson.annotation.JsonInclude.Include
import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMapper, PropertyNamingStrategy}
import com.fasterxml.jackson.module.scala.DefaultScalaModule

import scala.concurrent.ExecutionContext


package object json {
  val objectMapper = new ObjectMapper()
    .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
    .setSerializationInclusion(Include.NON_EMPTY)
    .setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE)
    .registerModule(DefaultScalaModule)

  implicit class ObjAsJsonUsingJackson(obj: Any) {
    def asJson: String = objectMapper.writeValueAsString(obj)
  }

  implicit class StringJsonAsCaseClass(json: String) {
    def asObject[T](implicit m: Manifest[T]): T = objectMapper.readValue(json, m.runtimeClass).asInstanceOf[T]
  }

  implicit def jsonMarshaller[T]: ToEntityMarshaller[T] =
    withFixedContentType(ContentTypes.`application/json`) { any =>
      HttpEntity(ContentTypes.`application/json`, any.asJson)
    }

  implicit def jsonUnmarshaller[T](implicit m: Manifest[T], materializer: Materializer): FromRequestUnmarshaller[T] =
    Unmarshaller[HttpRequest, T] {
      implicit ec: ExecutionContext => r => Unmarshal(r.entity).to[String].map(_.asObject[T])
    }
} 
开发者ID:gabfssilva,项目名称:akka-http-microservice-templates,代码行数:40,代码来源:json.scala


示例3: IdResult

//设置package包名称以及导入依赖的类
package io.buoyant.linkerd.admin

import com.fasterxml.jackson.annotation.JsonInclude.Include
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.scala.DefaultScalaModule
import com.fasterxml.jackson.module.scala.experimental.ScalaObjectMapper
import com.twitter.finagle.Service
import com.twitter.finagle.http._
import com.twitter.io.Buf
import com.twitter.util.{Future, Return, Throw, Try}
import io.buoyant.router.RoutingFactory
import io.buoyant.router.RoutingFactory.{IdentifiedRequest, UnidentifiedRequest}

case class IdResult(path: Option[String] = None, dtab: Option[String] = None, error: Option[String] = None)

object Json {
  private[this] val mapper = new ObjectMapper with ScalaObjectMapper
  mapper.registerModule(DefaultScalaModule)
  mapper.setSerializationInclusion(Include.NON_EMPTY)

  def write[T](t: T): Buf =
    Buf.ByteArray.Owned(mapper.writeValueAsBytes(t))
}

class HttpIdentifierHandler(
  identifiersByLabel: Map[String, RoutingFactory.Identifier[Request]]
) extends Service[Request, Response] {

  def apply(req: Request): Future[Response] = {
    val results = identifiersByLabel.mapValues { id =>
      id(req).transform {
        case Return(IdentifiedRequest(dst, req1)) =>
          Future.value(IdResult(Some(dst.path.show), Some(dst.dtab.show)))
        case Return(unidentified: UnidentifiedRequest[Request]) =>
          Future.value(IdResult(error = Some(unidentified.reason)))
        case Throw(e) =>
          Future.value(IdResult(error = Some(e.getMessage)))
      }
    }

    Future.collect(results).map { r =>
      val rsp = Response()
      rsp.content = Json.write(r)
      rsp.contentType = MediaType.Json
      rsp
    }
  }
} 
开发者ID:linkerd,项目名称:linkerd,代码行数:49,代码来源:HttpIdentifierHandler.scala


示例4: JsonUtils

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

import java.io.InputStream
import java.text.SimpleDateFormat

import com.fasterxml.jackson.annotation.JsonInclude.Include
import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMapper, SerializationFeature}
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
import com.fasterxml.jackson.module.scala.DefaultScalaModule
import com.fasterxml.jackson.module.scala.experimental.ScalaObjectMapper


object JsonUtils {

  private val Mapper = getObjectMapper
  private val Wrapper = getObjectMapper.configure(SerializationFeature.WRAP_ROOT_VALUE, true)

  def toJsonStr(value: Any): String = Mapper.writeValueAsString(value)

  def toJson(value: Any): Array[Byte] = Mapper.writeValueAsBytes(value)

  def toWrappedJson(value: Any): String = Wrapper.writeValueAsString(value)

  def toJsonPrettyPrint(value: Any): String = Mapper.writer().withDefaultPrettyPrinter().writeValueAsString(value)

  def fromJson[T](json: String)(implicit m: Manifest[T]): T = Mapper.readValue[T](json)

  def fromJson[T](json: String, clazz: Class[T]): T = Mapper.readValue(json, clazz)

  def fromJson[T](is: InputStream)(implicit m: Manifest[T]): T = Mapper.readValue[T](is)

  def fromJson[T](bytes: Array[Byte])(implicit m: Manifest[T]): T = Mapper.readValue[T](bytes)

  private def getObjectMapper = {
    val objectMapper = new ObjectMapper() with ScalaObjectMapper
    objectMapper.registerModule(DefaultScalaModule)
      .registerModule(new JavaTimeModule())
      .registerModule(new Jdk8Module())
      .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, SerializationFeature.INDENT_OUTPUT)
      .disable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE, DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
      .setSerializationInclusion(Include.NON_NULL)
      .setSerializationInclusion(Include.NON_ABSENT)
      .enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
      .setDateFormat(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX"))
    objectMapper
  }
} 
开发者ID:atomist,项目名称:artifact-source,代码行数:49,代码来源:JsonUtils.scala



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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