本文整理汇总了Scala中com.fasterxml.jackson.databind.SerializationFeature类的典型用法代码示例。如果您正苦于以下问题:Scala SerializationFeature类的具体用法?Scala SerializationFeature怎么用?Scala SerializationFeature使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SerializationFeature类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: BaseBDBEntity
//设置package包名称以及导入依赖的类
package db
import java.util.{Date, UUID}
import com.fasterxml.jackson.databind.{SerializationFeature, ObjectMapper}
import com.fasterxml.jackson.module.scala.DefaultScalaModule
import com.fasterxml.jackson.module.scala.experimental.ScalaObjectMapper
import tools._
import common._
import Tool._
class BaseBDBEntity[+Self <: BaseBDBEntity[Self]](tableName: String) extends BDBEntity(tableName) {
def toJson: String = {
BaseBDBEntity.map.writeValueAsString(this)
}
def fromJson(json: String): Self = {
BaseBDBEntity.map.readValue(json, this.getClass).asInstanceOf[Self]
}
//????????????
def changeUpdateBean(): Self = {
fromJson(toJson)
}
override def queryById(id: String, fields: String*): Option[Self] = {
super.queryById(id,fields:_*) map (_.asInstanceOf[Self])
}
override def queryByIds(idName: String, ids: List[Long], fields: String*): List[Self] = {
super.queryByIds(idName,ids,fields:_*) map (_.asInstanceOf[Self])
}
//????????????
override def queryPage(where: String, pageNum: Int, pageSize: Int, fields: String*):List[Self] = {
val list = super.queryPage(where, pageNum, pageSize,fields: _*)
list map (_.asInstanceOf[Self])
}
}
object BaseBDBEntity {
private val map = new ObjectMapper() with ScalaObjectMapper
map.registerModule(DefaultScalaModule)
map.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false)
}
//??????
class LoanData(val id:String=UUID.randomUUID().toString,val Title:String="",val text:String="",val createTime:Date=new Date())extends BaseBDBEntity[LoanData]("LoanData")
开发者ID:livehl,项目名称:paipai,代码行数:49,代码来源:BDBClass.scala
示例2: 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
示例3: GetCommand
//设置package包名称以及导入依赖的类
package command
import java.nio.file.{Files, Path, Paths}
import com.fasterxml.jackson.databind.SerializationFeature
import command.GetCommand.JsRecord
import core.storage.{ReadOnlyBigStorage, RealDirectory, Storage}
import org.slf4j.Logger
import utils.Js
import scala.collection.mutable.ArrayBuffer
case class GetCommand() extends Command {
override def isVerbose: Boolean = false
override def run(log: Logger, params: Array[String]): Unit = {
if (params.length < 3) {
exitError("Usage1: get <db-dir> <table-name> <record-id>\n" +
"Usage2: get <base-db-dir> <table-name> <record-id> <year> [more-years...] ")
}
val baseDbDir = Paths.get(params(0))
val tableName = params(1)
val recordId = params(2).toInt
val dbDirs: Seq[Path] =
if (params.length > 3) {
val years: Array[String] = params.drop(3)
years.map(baseDbDir.resolve)
} else Seq(baseDbDir)
val mapper = Js.newMapper.configure(SerializationFeature.INDENT_OUTPUT, true)
var records = new ArrayBuffer[JsRecord]()
for (dbDir <- dbDirs) {
if (!Files.isDirectory(dbDir)) exitError("No database in dir " + dbDir.toAbsolutePath)
val big = new ReadOnlyBigStorage(new RealDirectory(dbDir))
if (big.storages.isEmpty) exitError("No database in dir " + dbDir.toAbsolutePath)
records ++= big.getRecords(tableName, recordId).map {r =>
JsRecord(timestamp = r.timestamp, tableName = r.tableName, id = r.id, data = new Predef.String(r.data, Storage.Charset))
}
big.close()
}
println(mapper.writeValueAsString(records.sortBy(_.timestamp)))
}
}
object GetCommand {
case class JsRecord(timestamp: Long, tableName: String, id: Int, data: String)
}
开发者ID:citrum,项目名称:log-server,代码行数:52,代码来源:GetCommand.scala
示例4: BaseUnitTest
//设置package包名称以及导入依赖的类
package com.skn.common.view
import java.time.LocalDateTime
import com.fasterxml.jackson.databind.SerializationFeature
import com.skn.api.view.jsonapi.{JsonApiJacksonFormat, JsonApiMapper}
import com.skn.api.view.jsonapi.JsonApiModel.{ObjectKey, RootObject}
import com.skn.api.view.model.ViewLink
import com.skn.api.view.model.mapper.ReadFeatures.AbsentValueAsNull
import com.skn.api.view.model.mapper._
import com.typesafe.scalalogging._
import org.scalatest.{FlatSpec, Matchers}
import org.slf4j.LoggerFactory
class BaseUnitTest extends FlatSpec with Matchers
{
protected val logger = Logger(LoggerFactory.getLogger(classOf[BaseUnitTest]))
protected val mapper = new JsonApiMapper
def mappers = new {
val jacksonMapper = JsonApiJacksonFormat.createMapper()
jacksonMapper.enable(SerializationFeature.INDENT_OUTPUT)
val viewWriter = new DefaultViewWriter(new SimpleLinkDefiner)
val viewReader = new DefaultViewReader(Map[ReadFeatures, Boolean](AbsentValueAsNull() -> true))
val jsonViewWriter = new JsonApiViewWriter(viewWriter, root => jacksonMapper.writeValueAsString(root))
val jsonViewReader = new JsonApiViewReader(viewReader, json => jacksonMapper.readValue(json, classOf[RootObject]))
}
def data = new {
val itemName = "Js string value"
val item = createNewItem()
val itemData = mappers.viewWriter.write(item)
val itemDataStr = mappers.jsonViewWriter.write(item)
val itemWithNull = TestSimple(ObjectKey("fg", 0), null, 1)
def createNewItem() = TestView(itemName,
5, new Home("TH"), Some(0L),
Some(new ViewLink(TestLink(1L, Some(LocalDateTime.now())))),
Some(CustomObject(Some("customName"), 34423, Some(List(3.4, 4.5)))))
}
}
开发者ID:AlexeyIvanov8,项目名称:json-api-mapper,代码行数:43,代码来源:BaseUnitTest.scala
示例5: JSON
//设置package包名称以及导入依赖的类
package jesse.lee.util
import com.fasterxml.jackson.databind.SerializationFeature
object JSON {
import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMapper}
import com.fasterxml.jackson.module.scala.DefaultScalaModule
import com.fasterxml.jackson.module.scala.experimental.ScalaObjectMapper
private val mapper = new ObjectMapper() with ScalaObjectMapper
mapper.registerModule(DefaultScalaModule)
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
mapper.configure(SerializationFeature.FAIL_ON_UNWRAPPED_TYPE_IDENTIFIERS, false)
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false)
def read[T](text: String)(implicit m: Manifest[T]): Option[T] = {
try {
Some(mapper.readValue[T](text))
} catch {
case e: Throwable => None
}
}
def write(item: AnyRef): String = {
mapper.writeValueAsString(item)
}
}
开发者ID:wracker1,项目名称:ticket-booker,代码行数:29,代码来源:JSON.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: AppConfig
//设置package包名称以及导入依赖的类
package com.github.tweets.config
import com.fasterxml.jackson.databind.{SerializationFeature, ObjectMapper}
import com.fasterxml.jackson.module.scala.DefaultScalaModule
import org.springframework.context.annotation.{Bean, Configuration}
import org.springframework.http.converter.StringHttpMessageConverter
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
import org.springframework.web.client.RestTemplate
import scala.collection.JavaConversions._
@Configuration
private class AppConfig {
@Bean
def objectMapper(): ObjectMapper = {
val om = new ObjectMapper()
om.registerModule(DefaultScalaModule)
om.enable(SerializationFeature.INDENT_OUTPUT)
om
}
@Bean
def restTemplate(jacksonMessageConverter: MappingJackson2HttpMessageConverter): RestTemplate = {
val restTemplate = new RestTemplate()
restTemplate.setMessageConverters(List(jacksonMessageConverter, new StringHttpMessageConverter))
restTemplate
}
@Bean
def jacksonMessageConverter(objectMapper: ObjectMapper) = new MappingJackson2HttpMessageConverter(objectMapper)
}
开发者ID:andrei-l,项目名称:tweets-for-github-projects-gatherer,代码行数:32,代码来源:AppConfig.scala
示例8: 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
示例9: 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
示例10: Implicits
//设置package包名称以及导入依赖的类
package net.jxpress.jackson4s
import com.fasterxml.jackson.databind.{SerializationFeature, ObjectMapper}
import com.fasterxml.jackson.datatype.joda.JodaModule
import com.fasterxml.jackson.module.scala.DefaultScalaModule
import scala.reflect.ClassTag
object Implicits {
implicit val DefaultMapper: ObjectMapper =
new ObjectMapper().registerModule(DefaultScalaModule)
.registerModule(new JodaModule())
.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
.configure(SerializationFeature.WRITE_DATES_WITH_ZONE_ID, true)
implicit class JsonParser(val json: String) extends AnyVal {
def parseAs[T](implicit om: ObjectMapper, tag: ClassTag[T]): T = {
om.readValue(json, tag.runtimeClass.asInstanceOf[Class[T]])
}
}
}
开发者ID:jxpress,项目名称:jackson4s,代码行数:22,代码来源:Implicits.scala
示例11: 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
示例12: 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.databind.SerializationFeature类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论