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

Scala JsonInclude类代码示例

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

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



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

示例1: JsonObjectMapper

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

import javax.inject.Singleton

import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMapper, SerializationFeature}
import com.fasterxml.jackson.module.scala.DefaultScalaModule
import com.fasterxml.jackson.module.scala.experimental.ScalaObjectMapper
import de.stema.pullrequests.dto.PullRequestDTO

import scala.reflect.ClassTag
import scala.util.{Failure, Success, Try}

@Singleton
class JsonObjectMapper {
  private lazy val mapper = new ObjectMapper with ScalaObjectMapper
  mapper.registerModule(DefaultScalaModule)
  mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
  mapper.configure(SerializationFeature.INDENT_OUTPUT, true)
  mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY)
  mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)

  def getInstance[T](json: String)(implicit ct: ClassTag[T]): T =
    Try {
      mapper.readValue(json, ct.runtimeClass).asInstanceOf[T]
    } match {
      case Success(instance) => instance
      case Failure(e) => throw new IllegalStateException(s"Error during parsing of '$json'", e)
    }

  def getInstances[T](json: String)(implicit ct: ClassTag[T]): Seq[PullRequestDTO] =
    Try {
      mapper.readValue[Seq[PullRequestDTO]](json)
    } match {
      case Success(instances) => instances
      case Failure(e) => throw new IllegalStateException(s"Error during parsing of '$json'", e)
    }
} 
开发者ID:callidustaurus,项目名称:github-api,代码行数:39,代码来源:JsonObjectMapper.scala


示例2: JacksonMapper

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

import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMapper}
import com.fasterxml.jackson.dataformat.javaprop.JavaPropsMapper
import com.fasterxml.jackson.module.scala.DefaultScalaModule

object JacksonMapper extends ObjectMapper {
  configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true)
  registerModule(DefaultScalaModule)
  setSerializationInclusion(JsonInclude.Include.NON_ABSENT)
}


// Instead of converting to/from JSON, this converts to/from nested key/value properties.
object JacksonPropertyMapper extends JavaPropsMapper {
  configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true)
  registerModule(DefaultScalaModule)
  setSerializationInclusion(JsonInclude.Include.NON_ABSENT)

  def productToKeyVals(p: Product): List[(String, String)] = {
    // This is a naive two-stage algorithm that works simply. Maybe it could be improved later.
    val props = writeValueAsString(p)
    val lines = props.split('\n')
    val keyVals =
      for (line <- lines
           if line.length > 1) yield {
        divide(line, '=')
      }
    keyVals.toList
  }

  
  private def divide(s: String, c: Char): (String, String) = {
    val i = s.indexOf(c)
    if (i < 0) s -> ""
    else {
      val w1 = s.substring(0, i)
      val rest = s.substring(i + 1)
      w1 -> rest
    }
  }
} 
开发者ID:hmrc,项目名称:bank-account-reputation-frontend,代码行数:44,代码来源:JacksonMapper.scala


示例3: 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


示例4: JacksonSupport

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

import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.core.JsonParser
import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMapper}
import com.fasterxml.jackson.module.scala.DefaultScalaModule
import com.fasterxml.jackson.module.scala.experimental.ScalaObjectMapper

object JacksonSupport {

  val mapper: ObjectMapper with ScalaObjectMapper = new ObjectMapper with ScalaObjectMapper
  mapper.registerModule(DefaultScalaModule)

  mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL)
  mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
  mapper.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, false)
  mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true)
  mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true)
  mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true)
} 
开发者ID:51zero,项目名称:eel-sdk,代码行数:21,代码来源:JacksonSupport.scala


示例5: JsonUtil

//设置package包名称以及导入依赖的类
package uk.ac.wellcome.utils

import com.fasterxml.jackson.databind.annotation.JsonSerialize
import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMapper}
import com.fasterxml.jackson.module.scala.experimental.ScalaObjectMapper
import com.fasterxml.jackson.module.scala.DefaultScalaModule

import scala.util.Try

object JsonUtil {
  val mapper = new ObjectMapper() with ScalaObjectMapper

  mapper.registerModule(DefaultScalaModule)
  mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
  mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY)

  def toJson(value: Any): Try[String] =
    Try(mapper.writeValueAsString(value))

  def toMap[V](json: String)(implicit m: Manifest[V]) =
    fromJson[Map[String, V]](json)

  def fromJson[T](json: String)(implicit m: Manifest[T]): Try[T] =
    Try(mapper.readValue[T](json))
} 
开发者ID:wellcometrust,项目名称:platform-api,代码行数:27,代码来源:JsonUtil.scala


示例6: ProjectDefaultJacksonMapper

//设置package包名称以及导入依赖的类
package works.weave.socks.aws.orders

import com.fasterxml.jackson.annotation.JsonAutoDetect
import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.annotation.PropertyAccessor
import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.SerializationFeature
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
import com.fasterxml.jackson.module.scala.DefaultScalaModule

object ProjectDefaultJacksonMapper {
  def build() : ObjectMapper = {
    val mapper = new ObjectMapper()

    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
    mapper.setSerializationInclusion(JsonInclude.Include.ALWAYS)
    mapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY)
    mapper.enable(SerializationFeature.INDENT_OUTPUT)
    mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)

    val javaTime : JavaTimeModule = new JavaTimeModule
    mapper.registerModule(javaTime)

    val scalaModule = new DefaultScalaModule()
    mapper.registerModule(scalaModule)

    mapper
  }
} 
开发者ID:Compositional,项目名称:orders-aws,代码行数:31,代码来源:ProjectDefaultJacksonMapper.scala


示例7: CatalogueBooleanProductAttribute

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

import com.fasterxml.jackson.annotation.JsonInclude

@JsonInclude(JsonInclude.Include.NON_NULL)
case class CatalogueBooleanProductAttribute(value: Boolean,
                                            label: String = "",
                                            facet: String,
                                            referenceText: String = "",
                                            referenceUrl: String = "",
                                            evidenceKinds: List[EvidenceKind] = Nil,
                                            relatedProducts: List[String] = Nil) extends CatalogueAttribute {
  def kind = "Boolean"
} 
开发者ID:UKHomeOffice,项目名称:product-catalogue,代码行数:15,代码来源:CatalogueBooleanProductAttribute.scala


示例8: CatalogueIntegerProductAttribute

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

import com.fasterxml.jackson.annotation.JsonInclude

@JsonInclude(JsonInclude.Include.NON_NULL)
case class CatalogueIntegerProductAttribute(value: Int,
                                            label: String = "",
                                            facet: String,
                                            referenceText: String = "",
                                            referenceUrl: String = "",
                                            evidenceKinds: List[EvidenceKind] = Nil,
                                            relatedProducts: List[String] = Nil) extends CatalogueAttribute {
  def kind = "Integer"
} 
开发者ID:UKHomeOffice,项目名称:product-catalogue,代码行数:15,代码来源:CatalogueIntegerProductAttribute.scala


示例9: CatalogueBigDecimalProductAttribute

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

import com.fasterxml.jackson.annotation.JsonInclude

@JsonInclude(JsonInclude.Include.NON_NULL)
case class CatalogueBigDecimalProductAttribute(value: BigDecimal,
                                               label: String = "",
                                               facet: String,
                                               referenceText: String,
                                               referenceUrl: String,
                                               evidenceKinds: List[EvidenceKind] = Nil,
                                               relatedProducts: List[String] = Nil) extends CatalogueAttribute {
  def kind = "Decimal"
} 
开发者ID:UKHomeOffice,项目名称:product-catalogue,代码行数:15,代码来源:CatalogueBigDecimalProductAttribute.scala


示例10: CatalogueAttributeDto

//设置package包名称以及导入依赖的类
package cjp.catalogue.service

import cjp.catalogue.model.{CatalogueAttribute, EvidenceKind}

import com.fasterxml.jackson.annotation.JsonInclude

@JsonInclude(JsonInclude.Include.NON_NULL)
case class CatalogueAttributeDto(value: Any,
                                 label: String,
                                 facet: String,
                                 referenceText: String,
                                 referenceUrl: String,
                                 evidenceKinds: List[EvidenceKind] = Nil,
                                 relatedProducts: List[RelatedProductSummary] = Nil,
                                 validValues : Map[String,Int] = Map())


case class RelatedProductSummary(name: String, title: String) 
开发者ID:UKHomeOffice,项目名称:product-catalogue,代码行数:19,代码来源:CatalogueAttributeDto.scala


示例11: Jackson

//设置package包名称以及导入依赖的类
package teleporter.integration.utils

import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMapper, SerializationFeature}
import com.fasterxml.jackson.module.scala.DefaultScalaModule
import com.fasterxml.jackson.module.scala.experimental.ScalaObjectMapper


object Jackson {
  val mapper = new ObjectMapper() with ScalaObjectMapper
  mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL)
    .disable(SerializationFeature.FAIL_ON_EMPTY_BEANS)
    .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
    .registerModule(DefaultScalaModule)

  implicit def toStr[T <: AnyRef](o: T): String = {
    mapper.writeValueAsString(o)
  }
} 
开发者ID:huanwuji,项目名称:teleporter,代码行数:20,代码来源:Jackson.scala


示例12: MongoComponent

//设置package包名称以及导入依赖的类
package teleporter.integration.component.mongo

import java.util.Date

import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMapper, SerializationFeature}
import com.fasterxml.jackson.module.scala.DefaultScalaModule
import com.fasterxml.jackson.module.scala.experimental.ScalaObjectMapper
import org.bson.json.{JsonMode, JsonWriterSettings}
import org.mongodb.scala.bson._
import org.scalatest.FunSuite


//case class Person(id: Long, name: String, birth: Date)

class MongoComponent$Test extends FunSuite {
  test("bson to json") {
    val mapper = new ObjectMapper() with ScalaObjectMapper
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL)
    mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS)
    mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
    mapper.registerModule(new Bson2JsonModule)
    mapper.registerModule(DefaultScalaModule)
    val bsonDoc = BsonDocument(
      "id" ? BsonObjectId(),
      "string" ? BsonString("aa"),
      "int" ? BsonInt32(3434),
      "long" ? BsonInt64(43343L),
      "double" ? BsonDouble(3434.33f),
      "date" ? BsonDateTime(new Date())
    )
    println(bsonDoc.toJson(new JsonWriterSettings(JsonMode.SHELL)))
    //    println(bsonDoc.toJson(new JsonWriterSettings()))
    val str = mapper.writeValueAsString(bsonDoc)
    println(str)
  }
  test("json to bson") {
    val mapper = new ObjectMapper() with ScalaObjectMapper
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL)
    mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS)
    mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
    mapper.registerModule(new Json2BsonModule)
    mapper.registerModule(DefaultScalaModule)
    val map = Map("int" ? 3434, "long" ? 3433333333333333343L, "float" ? 434.33f, "double" ? 343.4343d, "date" ? new Date())
    println(mapper.writeValueAsString(map))
  }
  test("str to bson") {
    val bson = BsonDocument(
      """
        |{id:3434343434333}
      """.stripMargin)
    println(bson)
  }
} 
开发者ID:huanwuji,项目名称:teleporter,代码行数:55,代码来源:MongoComponent$Test.scala


示例13: Yaml

//设置package包名称以及导入依赖的类
package com.sk.app.proxmock.toolset.serialization

import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.core.JsonParser
import com.fasterxml.jackson.databind.{ObjectMapper, SerializationFeature}
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory
import com.fasterxml.jackson.module.scala.DefaultScalaModule
import com.sk.app.proxmock.toolset.serialization.betterpolymorphism.BetterPolymorphismModule


object Yaml {
  private val mapper = new ObjectMapper(new YAMLFactory())
  mapper.registerModule(DefaultScalaModule)
  mapper.registerModule(BetterPolymorphismModule())

  mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL)
  mapper.enable(JsonParser.Feature.ALLOW_YAML_COMMENTS)
  mapper.enable(SerializationFeature.INDENT_OUTPUT)

  def parse[T](yaml: String, clazz: Class[T]): T =
    mapper.readValue(yaml, clazz)

  def serialize[T](o: T): String =
    mapper.writeValueAsString(o)
} 
开发者ID:szymonkudzia,项目名称:proxmock,代码行数:26,代码来源:Yaml.scala



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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