Hi,

One idiom for deconstructing a Map is to use a pattern match:
myMap.map { case (k, v) => ... }.

For instance:

  val json = ("books" ->
    books.map { b =>
      ("id" -> b.id) ~
      ("tags" -> b.tags.map { case (k, v) => JField(k, v) }.toList)
    }
  )

Note, the explicit call toList is required since JsonDSL provides an
implicit conversion from List[JField] to JObject (not from Iterable
[JField]).

Cheers Joni

On 16 marras, 08:44, Tate <jones.t...@gmail.com> wrote:
> Hi all,
>
> I am pretty new to Scala and Lift so this question may not be pitched
> or explained correctly.
>
> I have an abstract class called Book that is created via Object Book.
> No troubles with this.
>
> abstract class Book {
>     val tags : Map[String,String]
>     val id : String
>
> }
>
> I wish to serialize this to a Json response, but I am having troubles
> resolving the serialization of the Map (tags) to a simple name value
> pair.
>
> eg. Map(Title -> RedHat Unleashed,  Category ->OS)
>
> Json response.
>
>   "book": {
>     "id": "ID1234",
>     "tags": {
>         "Title": "RedHat Unleased",
>         "Category": "OS"
>      }
>   }
>
>  val json = ("books" ->
>                     books.map { b =>
>                         ("id" -> b.id) ~
>                         ("tags" ->
>                             b.tags.map { t =>
>                                ==> this is where I need to create a
> List(JsonAST.JField(key,value)...)) from the map
>                             }
>                         )
>                     }
>                    )
>
> This is probably a general Scala question with maps, but I having
> difficult finding good examples that transform a map into a list with
> new object content.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to