Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot convert nested Maps into json #33

Open
velvia opened this issue Nov 20, 2012 · 2 comments
Open

Cannot convert nested Maps into json #33

velvia opened this issue Nov 20, 2012 · 2 comments

Comments

@velvia
Copy link

velvia commented Nov 20, 2012

Hi, I'm using spray-json 1.2.2 and get this error:

scala> Map("a" -> Map("b" -> 2), "b" -> Map()).toJson
:14: error: Cannot find JsonWriter or JsonFormat type class for scala.collection.immutable.Map[String,scala.collection.immutable.Map[_ <: String, Int]]
Map("a" -> Map("b" -> 2), "b" -> Map()).toJson
^
Doesn't seem like it should be that hard to fix.

@jrudolph jrudolph added the Bug label Mar 7, 2014
@jrudolph jrudolph added this to the Next bugfix release milestone Mar 7, 2014
@jrudolph
Copy link
Member

Right, mapFormat seems a bit broken requiring a JsonFormat[K] for the key. We cannot fix this right now as it would break binary compatibility.

@ancane
Copy link
Contributor

ancane commented Dec 2, 2016

Looks like heterogeneous map involved in this example. I guess, spray-json-shapeless could handle that.

Regular nested maps work fine though:

scala> Map("a" -> Map("b" -> 2), "b" -> Map("c" -> 3)).toJson
res0: spray.json.JsValue = {"a":{"b":2},"b":{"c":3}}

Seems like it's not a bug. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants