Reputation: 921
Please explain whats wrong with the code, I'm getting the output as {} empty. How should I get the json output.
val values = (1 to 10).toList
val topic = "linkedlists"
val gson = new GsonBuilder().create()
val output=gson.toJson(values,classOf[List[Int]])
println(output)
Upvotes: 0
Views: 448
Reputation: 31252
because java.
you can use java.util.List
not scala.collection.immutable.List
example,
import scala.collection.JavaConverters._
val list = (1 to 10).asJava
val gson = new GsonBuilder().create()
gson.toJson(list, classOf[java.util.List[Int]]) shouldBe "[1,2,3,4,5,6,7,8,9,10]"
Upvotes: 1