question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Strange serialization of scala Map

See original GitHub issue

Hey,

I tried to serialize this with upicke 0.2.2, scala 2.11.2, scala.js 0.5.3 :

case class RequestMessage(requestId: String, op: String, processor: String, args: Map[String, String])
write(RequestMessage(
      "1d6d02bd-8e56-421d-9438-3bd6d0079ff1",
      "eval",
      "",
      Map(
        "gremlin" -> "g.v(x).out",
        "bindings" -> "",
        "language" -> "gremlin-groovy"
      )
    )
)

{"requestId":"1d6d02bd-8e56-421d-9438-3bd6d0079ff1","op":"eval","processor":"","args":[["gremlin","g.v(x).out"],["bindings",""],["language","gremlin-groovy"]]}

Do I need to implement unapply method for maps too in case classes? The map is serialized into some sort of list of arrays. Even if I serialize it directly it resolves to :

[["gremlin","g.v(x).out"],["bindings",""],["language","gremlin-groovy"]]

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
l15k4commented, Aug 23, 2014

For future reference, with scala.js the best possible way to handle Map[K, Any] is :

import scala.scalajs.js.Dynamic.{literal => lit}
import scala.scalajs.js.JSON._
stringify(
      lit(
        "gremlin" -> "g.v(x).out",
        "language" -> "gremlin-groovy",
        "bindings" -> lit("x" -> 1)
      )
    )
0reactions
l15k4commented, Aug 22, 2014

There is just one thing that is really hard to deal with and that’s the Map[K, Any] I hit dead end with… I wanted to use shapeless HMap, but it doesn’t give you keySet or let you iterate it. Would you please uplade the README and tell people what alternatives do they have ? That would be highly appreciated.

Messaging protocol of the server counterpart I’m communicating with is based on nested maps of various value data types : primitives, map and list of primitives

Read more comments on GitHub >

github_iconTop Results From Across the Web

Strange serialization of scala Map - com-lihaoyi/upickle - GitHub
Hey, I tried to serialize this with upicke 0.2.2, scala 2.11.2, scala.js 0.5.3 : case class RequestMessage(requestId: String, op: String, ...
Read more >
Map can not be serializable in scala? - Stack Overflow
I am new to Scala. How come the "map" function is not serializable? How to make it serializable? For example, if my code...
Read more >
Large Scala Maps Fail Serialization - Imran Rashid
Took me a little while to figure it out, but it turns out that large Maps in Scala are not serializable. The exception...
Read more >
Scala Standard Library 2.13.4 - scala.collection.Map
Appends all elements of this map to a string builder using start, end, and separator strings.
Read more >
Java and JSON – Jackson Serialization with ObjectMapper
Jackson serializes a Map as a JSON object whose keys are the keys' toString() representation (in this case it's the value itself). The...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found