Question

I have a collection of strings.

When I iterate through the collection (using .map()) to output the values, the string "Lipsum" gets outputed with double quotes

Inside Scala class:

case class Container(id: Int, name: String, url: String)
val tags = (i \\ "tags").flatMap{
    tag =>
        tag.as[JsArray].value.map {
            element => Container(element \ "id", element \ "name", element \ "url")
        }
}

Inside Template:

<div class="item">
    @tags.element.map { item =>
        @item.name
    }
</div>

Collection output ( println(item.name) ):

List(Container(1957,"Lipsum","/lipsum"))

Current output of the string looks like this:

<div class="item">
"Lipsum"
</div>

Desired output:

<div class="item">
Lipsum
</div>

How can I get rid of the double quotes?

Thanks

Was it helpful?

Solution

element \ "name" gives you a JsValue. JsString.toString will add the double quotes.

I'm surprised that Container(element \ "id", element \ "name", element \ "url") compiles, but this should work:

Container(element \ "id", (element \ "name").as[String], (element \ "url").as[String])
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top