json - Serializing scala map with gson returns "key" with every key -


new scala , tried searching couldn't find solution it. i've scala map shown below:

val mymap = map("foo" -> "baz") 

i want serialize using gson library , here's doing:

val json = new gson() val serializedmap = json.tojson(mymap) 

when print serializedmap "{"key1":"foo", "value1":"baz"}" expecting "{"foo": "baz"}"

what missing?

gson java library, has no special treatment of scala collections. seeing there internal instance variables found through reflection. if want use gson, need convert java collections:

import scala.collection.javaconverters._ mymap.asjava 

but may wish @ scala-specific json libraries also. there plenty of ones.


Comments

Popular posts from this blog

minify - Minimizing css files -

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -