Questions tagged [upickle]

µPickle is a lightweight serialization library for Scala and ScalaJS.

43 questions
0
votes
1 answer

Upickle: read an attribute that may be a String or Int as a String

I have a field that may come from a rest api as a String or Int, but when I read it I always want to read it as a String, i.e. if it comes as an Int I want to do a toString on it case class ZoneList( someField: Int, targetField:…
Nima
  • 170
  • 1
  • 5
0
votes
1 answer

How to unpickle CIFAR-10, load batches and split datasets?

Working on CIFAR-10 Dataset Classification using Convolutional Neural Networks. I am unable to understand: 1) where to extract CIFAR-10 dataset files 2) how to load the batches using pickle framework 3) split dataset into training data and test…
0
votes
1 answer

How to use the ReadWriter for parameterized types

I am trying to migrate to the latest version of upickle 0.7.1. Where I had previously passed around implicit Readers and Writers I believe I must now use a single ReadWriter and explicitly define them in a companion object for any case classes I…
user79074
  • 4,937
  • 5
  • 29
  • 57
0
votes
1 answer

How to read/write a generic class with upickle

Say I have the following trait: trait T { val x: Int } def foo(i: Int): T I would like to bet able to write and read this trait using upickle without knowing what the specific class is. e.g.: upickle.default.write(foo(3)) Such that I could…
user79074
  • 4,937
  • 5
  • 29
  • 57
0
votes
1 answer

Encode ujson.Value in Spark Dataset

Let's say I have these JSON lines stored is a text file. {"a": "...", "data": [{}]} {"a": "...", "data": [{"b": "..."}]} {"a": "...", "data": [{"d": "..."}]} {"a": "...", "data": [{"b": "...", "c": "..."}]} I would like to process the file to a…
Michel Hua
  • 1,614
  • 2
  • 23
  • 44
0
votes
0 answers

unpickling json into a case class with option

Consider this case class: case class Sample(status: String, message: Option[String]) Sample(status="OK") is serialized by play-json to JSON as { "status":"OK" } and Sample(status="OK", message=Some("message content")) { "status":"OK", …
mcku
  • 1,351
  • 12
  • 23
0
votes
1 answer

Why can't stringify convert back to json after parse

Say I define the following case classes: case class A(i: Int) case class B(str: String) case class T(a: A, b: B) I then convert to json, parse back and try to convert again as follows: val json = write(T(A(1), B("One"))) val parsed =…
user79074
  • 4,937
  • 5
  • 29
  • 57
0
votes
0 answers

Get the name of a case class attribute without reflection

I have a project based on ScalaJS and upickle. This means I do not have access to Scala reflection in my code on the JS side. I have a need to associate case class attributes with their names and am wondering if there is any way I can infer the name…
user79074
  • 4,937
  • 5
  • 29
  • 57
0
votes
0 answers

How to define custom upickle writer and reader

Supposing I have a case class whose members types are Scala/Java that I can't or want to modify, and that are not supported by uPickle default writer/reader. Is there a way to say to upickle how to manage it? To be more clear, let's take an…
ndesmoul
  • 103
  • 6
0
votes
1 answer

µPickle Couldn't derive type error on write

I'm trying to use µPickle in Scala.js to produce Json for Ajax request. Here is my code: import upickle._ import upickle.default._ case class FmData(name: String, comment: String) val data = write(FmData("name", "comment")) And I…
sergeda
  • 2,061
  • 3
  • 20
  • 43
0
votes
2 answers

upickle: invalid string value during deserialization

I am quite new in scala.js world so I decided to try it out on some small examples and one of them is quite simple get request with parsing of returning json back into scala entity. Please find code which does it below: def…
tkachuko
  • 1,956
  • 1
  • 13
  • 20
0
votes
1 answer

upickle read from scalaJS - upickle.Invalid$Data: String (data: 1)

From ScalaJS. import upickle.default._ import scala.scalajs.concurrent.JSExecutionContext.Implicits.queue case class Post(userId: Long, id: Long, title: String, body: String) @JSExport def posts() : Future[Seq[Post]] = { val txt = """[{ …
ses
  • 13,174
  • 31
  • 123
  • 226
0
votes
1 answer

What magic needed to use scala uPickle?

I'm trying to following the quickstart guide here https://lihaoyi.github.io/upickle-pprint/upickle/ Have set the dependency "com.lihaoyi" %%% "upickle" % "0.3.6", but the basics seem to fail: scala> import upickle.default._ import…
user48956
  • 14,850
  • 19
  • 93
  • 154
1 2
3