value classes in Spray JSON

582 views
Skip to first unread message

Sam Halliday

unread,
Dec 23, 2012, 9:43:21 PM12/23/12
to spray...@googlegroups.com
Hi all,

Are value case classes easily supported in Spray JSON?


Regards, Sam

Mathias

unread,
Dec 27, 2012, 7:40:50 AM12/27/12
to spray...@googlegroups.com
They should be.
Do you have any problems with them?

Cheers,
Mathias

---
mat...@spray.io
http://spray.io
> --
>
>

Samuel Halliday

unread,
Dec 27, 2012, 8:16:42 AM12/27/12
to spray...@googlegroups.com
Thanks Mathias,

I mean: what is the recommended JsonFormat to use for a case class? I would like the JSON representation to be one-layer deep. e.g.

case class MyValClass(val value: String) extends AnyVal

should marshall to

"value here"

and not

{
value: "value here"
}

is that supported?

--
Sam
> --
>
>

Mathias

unread,
Dec 27, 2012, 8:33:02 AM12/27/12
to spray...@googlegroups.com
Ok, I see now what you are getting at.

Support for "unboxed" JSON representation of single-member classes is certainly something that might be valuable.
However, since value classes are merely an implementation detail on the JVM side of things and do not add anything that structurally couldn't be modeled by "regular" single-member case classes I don't think it makes sense to handle them specially.
Logically value classes are just classes and therefore should not receive special treatment.

However, "unboxed" handling of single-member types is generally interesting, I have created an issue to track this:
https://github.com/spray/spray-json/issues/38

Thanks and cheers,
> --
>
>

Reply all
Reply to author
Forward
0 new messages