BigDecimal deserialization problem

93 views
Skip to first unread message

Filipe Lenfers

unread,
Mar 22, 2014, 7:59:57 PM3/22/14
to scalat...@googlegroups.com
Hi!

I need some help with BigDecimal deserialization.

I tried the instructions from here: http://www.scalatra.org/2.2/guides/formats/json.html and added this to my code:

  protected implicit val jsonFormats: Formats = DefaultFormats.withBigDecimal

I done this example code:

case class Test(value: BigDecimal) 
class BigDecimalTest extends MyAppStack with NativeJsonSupport {
  protected implicit val jsonFormats: Formats = DefaultFormats.withBigDecimal
  get("/") {
    Test(BigDecimal("1.23"))
  }
  post("/") {
    val o = parsedBody.extract[Test]
    println(o)
    o
  }
}


When I call the get method I receive:
{"value":1.23}

But when I try to send the same json to the post method I receive:
No usable value for value Do not know how to convert JDouble(1.23) into class scala.math.BigDecimal
org.json4s.package$MappingException: No usable value for value Do not know how to convert JDouble(1.23) into class scala.math.BigDecimal

I tried to use JacksonJsonSupport instead of NativeJsonSupport, but I runt into the same problem.

I'm using scalatra 2.2.2 and json4s 3.2.7.

Thanks for the help,
Filipe. 

Ivan Porto Carrero

unread,
Mar 22, 2014, 9:22:11 PM3/22/14
to scalat...@googlegroups.com
That is a bug in json4s, it's missing those clauses in a pattern match. 3.2.9-SNAPSHOT has a fix for it I think

---
Met vriendelijke groeten - Best regards - Salutations
Ivan Porto Carrero - Mob: +1 (415) 323-8084
Web: http://flanders.co.nz
Twitter: http://twitter.com/casualjim



--
You received this message because you are subscribed to the Google Groups "scalatra-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scalatra-use...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Filipe Lenfers

unread,
Mar 23, 2014, 4:49:20 PM3/23/14
to scalat...@googlegroups.com
Thanks!  I will try json4s 3.2.9-SNAPSHOT .

Regards, 
Filipe.


--
You received this message because you are subscribed to a topic in the Google Groups "scalatra-user" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/scalatra-user/xttZ_Dwwl0Y/unsubscribe.
To unsubscribe from this group and all its topics, send an email to scalatra-use...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--

Filipe Pais Lenfers
Reply all
Reply to author
Forward
0 new messages