upickle: Handling of lists

204 views
Skip to first unread message

Björn Julander

unread,
Oct 13, 2014, 8:40:46 AM10/13/14
to scal...@googlegroups.com

I want to unpickle a json like:
"values" :[["a1","b1","c1"],["a2","b2","c2"], ...]

Thus I have a list of lists where each inner list is fixed length of 3.

Using upickle to unpickle a list of (3) Strings to a tuple works nice:
read[(String,String,String)]("""["a1","b1","c1"]""")    ==>("a1","b1","c1")

But how would I write the same to get it into a case class?

I thought I would write something similar to:

case class Values(values:Seq[Value])
case class Value( (a:String,b:String,c:String) )



But I have to name the Value tuple something, which is fine, but then the unpickler assumes
that name in the json tag, I think, and I get a decode error.

Any tips on how I should craft case classes (or custom unpicklers?), to match the json, 'values', above?

// Björn

Benjamin Jackman

unread,
Oct 13, 2014, 5:52:14 PM10/13/14
to scal...@googlegroups.com
I haven't used upickle, but have you tried defining your own custom picklers as detailed here:

Björn Julander

unread,
Oct 14, 2014, 7:52:54 AM10/14/14
to scal...@googlegroups.com
Thanks for the reply! I was considering this, but it seemed like a bit overkill for
such a simple datatype. Perhaps I'll end up there eventually...

Haoyi Li

unread,
Nov 25, 2014, 6:54:47 PM11/25/14
to Björn Julander, scal...@googlegroups.com

That issue is basically this one; feel free to track it or to send a PR to fix for everyone else.

--
You received this message because you are subscribed to the Google Groups "Scala.js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-js+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scala-js/e353b38e-88fc-482e-ba98-ddd1ff98a6c0%40googlegroups.com.

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

Reply all
Reply to author
Forward
0 new messages