项目作者: mesosphere

项目描述 :
Deserialization support for Scala case classes, including proper handling of default values.
高级语言: Scala
项目地址: git://github.com/mesosphere/jackson-case-class-module.git
创建时间: 2014-04-02T21:44:14Z
项目社区:https://github.com/mesosphere/jackson-case-class-module

开源协议:

下载


Jackson Case Class Module

This project is currently unused by Mesosphere projects and will no longer be maintained. We will not be accepting contributions or releasing new versions of this. You are welcome to fork the repo for your own use.

Provides deserialization support for Scala case classes, including proper handling of default values.

Assumes that the default case class constructor’s arguments are sufficient for deserialization.

SBT:

  1. resolvers += "Mesosphere Public Repository" at "http://downloads.mesosphere.io/maven"
  2. libraryDependencies += "mesosphere" %% "jackson-case-class-module" % "0.1.2"

Maven:

  1. <repository>
  2. <id>mesosphere-public-repo</id>
  3. <name>Mesosphere Public Repo</name>
  4. <url>http://downloads.mesosphere.io/maven</url>
  5. </repository>
  6. <dependency>
  7. <groupId>mesosphere</groupId>
  8. <artifactId>jackson-case-class-module_2.10</artifactId>
  9. <version>0.1.2</version>
  10. </dependency>

Usage

NOTE: when using Jackson that case classes should be at the top level of your file to avoid issues that prevent jackson from being able to instantiate a new instance of your case class

  1. import mesosphere.jackson.CaseClassModule
  2. import com.fasterxml.jackson.module.scala.DefaultScalaModule
  3. val mapper = new ObjectMapper
  4. mapper.registerModule(DefaultScalaModule)
  5. mapper.registerModule(CaseClassModule)
  6. case class Person(name: String, age: Integer = 30)
  7. val readResult = mapper.readValue(
  8. """{ "name": "Alfonso" }""",
  9. classOf[Person]
  10. )
  11. assert(readResult.age == 30) // hooray