How to automatically marshall Boolean and other basic types to Json?

47 views
Skip to first unread message

Nicolau Werneck

unread,
Jun 13, 2015, 1:08:33 PM6/13/15
to akka...@googlegroups.com
I am playing around with akka-http 1.0-RC3. I can successfully serve `case class` objects marshalled into JSON, that's just fine. But I am unable to let the server marshall basic types that could be translated to JSON, e.g. integer or Boolean. Shouldn't just `import DefaultJsonProtocol._` be sufficient for the implicit conversions to happen? What else is missing? And how could I write a custom marshaller for a type like this? I haven't been able to find a good example yet...

Martynas Mickevičius

unread,
Jun 16, 2015, 3:27:15 AM6/16/15
to akka...@googlegroups.com
Hi Nicolau,

can you expand a bit more on your usecase?

A valid root object of the JSON document is only an object or an array. Therefore you can not marshall a single boolean or integer to JSON document. You must have a collection or a case class holding such a value.

On Sat, Jun 13, 2015 at 8:08 PM, Nicolau Werneck <nwer...@gmail.com> wrote:
I am playing around with akka-http 1.0-RC3. I can successfully serve `case class` objects marshalled into JSON, that's just fine. But I am unable to let the server marshall basic types that could be translated to JSON, e.g. integer or Boolean. Shouldn't just `import DefaultJsonProtocol._` be sufficient for the implicit conversions to happen? What else is missing? And how could I write a custom marshaller for a type like this? I haven't been able to find a good example yet...

--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.



--
Martynas Mickevičius
TypesafeReactive Apps on the JVM

Nicolau Werneck

unread,
Jun 16, 2015, 10:08:15 PM6/16/15
to akka...@googlegroups.com
All right then, I just packed what I needed on a list now. Thanks!    ++nic
Reply all
Reply to author
Forward
0 new messages