[2.0-Scala] Any example with lift-json? Help

200 views
Skip to first unread message

Sejensen

unread,
Jun 25, 2012, 5:51:56 AM6/25/12
to play-fr...@googlegroups.com
Hi everyone

I am looking to migrate my code to a Play 2 Scala app from unfiltered. (Unfiltered is still very cool, just that I need some fullstack stuff from Play, evolutions, templates, ...) 

In unfiltered I use lift-json and squeryl and this allows me to use case classes and very easy to and from json instead of the "anorm" json style in default play 2, which speeds up my mobile to backend coding.

I have read that I can code a custom body parser but as far as I can see that will make my actions more verbose (needs to add parser) and combined with play2.0-auth I have to change a module to make it work.

Have anybody gotten lift-json to work in play 2 in a clean and concise way? Any example for bodyparser etc would be really nice

Thank you very much in advance!
 /Steffen

Ludovico Fischer

unread,
Jun 25, 2012, 9:52:30 AM6/25/12
to play-fr...@googlegroups.com

Have anybody gotten lift-json to work in play 2 in a clean and concise way? Any example for bodyparser etc would be really nice

Thank you very much in advance!
 /Steffen

Normally, if you just include the library in your project dependencies, you can then import it any way you want in the code. Body parsers should not be different than any other code.

Ludovico

Sejensen

unread,
Jun 25, 2012, 2:37:14 PM6/25/12
to play-fr...@googlegroups.com
I think you misinterpreted my question.

I am looking for an example or guidance on how to switch from the standard play json to lift-json in a smart way. I know i can add lift-json as an dependency. Thats plain copy paste from my unfiltered app.

Its more the bodyparser part and how to avoid manually selecting the parser for all actions. Something that detects on content type and uses my json stuff instead.

Anybody else can help?

Thank you
Steffen

Manuel Bernhardt

unread,
Jun 25, 2012, 4:19:08 PM6/25/12
to play-fr...@googlegroups.com
Hi,

to the best of my knowledge, I think this method gets invoked when you
build an Action without specifying the body type:

https://github.com/playframework/Play20/blob/master/framework/src/play/src/main/scala/play/api/mvc/ContentTypes.scala#L506

which means that probably a way to get your lift-json parser to
automatically handle JSON would require e.g. to mixin a custom trait
in your controller that overrides the anyContent method and in the
case of json calls your own bodyparser, i.e.

object MyApplication extends Controller with LiftJsonParser { ... }

trait LiftJsonParser { this: Controller =>

override def anyContent: BodyParser[AnyContent] =
BodyParser("anyContent") { request =>
request.contentType match {
case Some("text/json") | Some("application/json") => {
// your code here
}
case _ => super.anyContent
}

}

See https://github.com/playframework/Play20/blob/master/framework/src/play/src/main/scala/play/api/mvc/ContentTypes.scala#L335
for an implementation example.

Manuel
> --
> You received this message because you are subscribed to the Google Groups
> "play-framework" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/play-framework/-/Gn4hSnjcaLwJ.
>
> To post to this group, send email to play-fr...@googlegroups.com.
> To unsubscribe from this group, send email to
> play-framewor...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/play-framework?hl=en.

高橋俊幸

unread,
Jun 25, 2012, 8:45:51 PM6/25/12
to play-fr...@googlegroups.com

Hi

I wrote a module for lift-json.
Does it meet your need ?
https://github.com/tototoshi/lift-json-play-module

--Toshi

2012/06/25 18:51 "Sejensen" <seje...@gmail.com>:

Sejensen

unread,
Aug 14, 2012, 2:29:30 PM8/14/12
to play-fr...@googlegroups.com
Sorry for the very late reply

But thank you very much for taking your time to write this module.

It helped me getting lift-json working with play.

Thanks once again.
Steffen
Reply all
Reply to author
Forward
0 new messages