µPickle is a lightweight serialization library for Scala and ScalaJS.
Questions tagged [upickle]
43 questions
8
votes
2 answers
uPickle and ScalaJS: sealed trait serialisation
I'm trying to get a basic upickle example to work and it seems I'm missing something here. I want to try out the example provided on the readme page for upickle
import upickle._
sealed trait A
@key("Bee") case class B(i: Int) extends A
case object…

Jean-Philippe Pellet
- 59,296
- 21
- 173
- 234
7
votes
1 answer
how to read json with an optional field serialized by a missing field, in upickle
I use upickle for serializing json in scalajs. I need to be able to parse optional fields, represented by a null value and by a missing field (standard json on the web).
With OptionPickler, I can accept nullable items.
However, how can I accept…

David Portabella
- 12,390
- 27
- 101
- 182
5
votes
2 answers
How to serialize/deserialize case class to js.Dynamic with uPickle
I am using uPickle/ScalaJS to deserialize a js.Dynamic object into a case class using this code fragment:
read[myClass](JSON.stringify(dynObj))
where myClass is the case class and dynObj is the js.Dynamic object.
Is there a boilerplate-free and…

nvalada
- 265
- 1
- 11
4
votes
5 answers
Dealing with optional field with lihaoyi ujson
I want to use ujson of the upickle library to extract an optional string from a json document. In some documents the json field exists, in others not.
When acessing the field and the field does not exist I get a NoSuchElementException:
val json =…

nemoo
- 3,269
- 4
- 38
- 51
3
votes
1 answer
Custom pickler for a tagged reader
I'm using uPickle 1.2.0. I have this example code:
import upickle._
import upickle.default._
import upickle.implicits.key
sealed trait Field
@key("TypeA") case class TypeA(val valueA: Int) extends Field
@key("TypeB") case class TypeB(val valueB:…

antonone
- 2,045
- 1
- 25
- 35
3
votes
1 answer
Serializing polymorphic types with µPickle
I am reading documentation for µPickle and searching the internet, but I was not able to find any mentions of one feature which is quite basic and I remember having it documented for perhaps all serialization libraries I was using before (Jackson,…

Suma
- 33,181
- 16
- 123
- 191
2
votes
1 answer
Scala - Error java.lang.NoClassDefFoundError: upickle/core/Types$Writer
I'm new to Scala/Spark, so please be easy on me :)
I'm trying to run an EMR cluster on AWS, running the jar file I packed with sbt package.
When I run the code locally, it is working perfectly fine, but when I'm running it in the AWS EMR cluster,…

matmiz
- 70
- 9
2
votes
2 answers
Unable to import upickle with Scalajs-react shared dependencies
i have a small problem. I am trying to use upickle lib. i have included it in my sharedDependencies as "com.lihaoyi" %%% "upickle" % "0.3.6". For some reason i am able to import upickle in my server project but it is still not available in my client…
user4833870
2
votes
1 answer
uPickle Writer for HList
I'm trying to create custom uPickle Writer for shapeless.HList transforming to simple array instead of complex nested object.
But i could not provide enough concrete evidence it could me mapped with my poly
I have this code:
import upickle.Js
import…

Odomontois
- 15,918
- 2
- 36
- 71
2
votes
1 answer
upickle gives a ScalaReflectionException when writing a case class
I have a simple case class:
object Margin {
def apply(top: Int, right: Int, bottom: Int, left: Int): Margin = {
Margin(Some(top), Some(right), Some(bottom), Some(left))
}
}
case class Margin(top: Option[Int], right: Option[Int], bottom:…

Julie
- 6,221
- 3
- 31
- 37
1
vote
1 answer
Is it possible to parse an empty sequence to an Obj?
I'm using Scala's uPickle to parse this JSON:
{ "somevalue": 1, "revenue": [], "boost": { ... } }
The problem is that "revenue" is sometimes an object, and sometimes it's an empty array. If it's an empty array, this means that the value is not…

antonone
- 2,045
- 1
- 25
- 35
1
vote
0 answers
Scala - Custom Encoder for Upickle/Ujson Library
I am working with the Upickle/Ujson and want to write a custom encoder to get the hang of things.
Suppose I have the following hierarchy (from the tutorial here: Link)
import upickle.default._
object TestDrive extends App {
sealed trait…

finite_diffidence
- 893
- 2
- 11
- 20
1
vote
1 answer
How to serialize generic case classes with µPickle?
The µPickle docs say generic case classes can be serialized:
Out of the box, uPickle supports writing and reading the following types:
Stand-alone case classes and case objects, and their generic equivalents,
However no example is given and I…

Suma
- 33,181
- 16
- 123
- 191
1
vote
1 answer
Custom writer/reader in upickle no longer works after upgrade to 0.7.1
I have my own custom DateTime class for which I wrote the following custom writer and reader:
val dtWriter = Writer[DateTime]{
case t => Js.Str(format(t))
}
val dtReader = Reader[DateTime]{
case Js.Str(time) =>
try {
…

user79074
- 4,937
- 5
- 29
- 57
1
vote
1 answer
How to access a pickled model file saved in desktop to Jupiter notebook?
I have a pickled model file on my desktop on Mac. I want to load it to my Jupyter notebook. However, when I try this code:
import pickle
file_1 = open('RFonevsrest2_model.sav', 'r')
loaded_model = pickle.load(file_1)
I get an error saying there is…

sayo
- 207
- 4
- 18