Wraps up jackson-scala-module for easier use
Scala
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
project/target/config-classes
src
.gitignore
README.mkd
build.sbt

README.mkd

Swaddle wraps up jackson-scala-module

It took me most of an afternoon to get all the pieces of jackson-scala-module put together in a way that I could actually use them. This is the result. Saved here largely for prosterity and easy linking.

import org.conbere.swaddle.Swaddle
import com.fasterxml.jackson.core.JsonParser

object Main {
  def main(args:Array[String]) {
    val swaddle = new Swaddle {
      val mapper = buildMapper
        .configure(JsonParser.Feature.ALLOW_NUMERIC_LEADING_ZEROS, true)
        .build        
    }

    println(swaddle.deserialize[Map[String,Int]]("""{ "x": 10 }"""))
    // => Map[String,Int]("x" -> 10)
    println(swaddle.deserialize[Map[String,Int]]("""{ "x": 0010 }"""))
    // => Map[String,Int]("x" -> 10)
  }
}