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.
Simply add the following dependency to libraryDependencies
"org.mdedetrich" %% "json4s-spire" % "1.3.0"
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 FixedPoint
s, you need
to create a different json4s Formats
for each case
implicit val fixedScale = FixedScale(10)
val formats = DefaultFormats.withBigDecimal ++ org.json4s.spire.Serializers.withDecimal
implicit val fixedScale = FixedScale(10)
val formats = DefaultFormats.withBigDecimal ++ org.json4s.spire.Serializers.withDouble
- More non trivial test cases need to be added