mdedetrich / json4s-spire

Spire wrappers for Json4s

GitHub

json4s-spire: Spire wrappers for Json4s

json4s-spire is a collection of sane wrappers for basic spire number types to json4s Json AST representation, allowing you to easily decompose spire values to Json and extract Json values into spire values. It is built for scala 2.10 and scala 2.11.

Installation

Simply add the following dependency to libraryDependencies

"org.mdedetrich" %% "json4s-spire" % "1.3.0"

Usage

json4s-spire comes with 2 modes, withDouble and withDecimal. withDouble converts JDouble to relevant spire types and vice versa, where as withDecimal converts JDecimal to relevant spire types and vice versa

The implicit val fixedScale is needed due to the spire FixedPoint type. If you need to change between different FixedPoints, you need to create a different json4s Formats for each case

withDecimal

implicit val fixedScale = FixedScale(10)
val formats = DefaultFormats.withBigDecimal ++ org.json4s.spire.Serializers.withDecimal

withDouble

implicit val fixedScale = FixedScale(10)
val formats = DefaultFormats.withBigDecimal ++ org.json4s.spire.Serializers.withDouble

TODO

  • More non trivial test cases need to be added