Pinky json sample

5 views
Skip to first unread message

Dmitry G

unread,
Oct 19, 2011, 3:02:03 PM10/19/11
to pinky webframework
Folks,

A pinky noob here.. Can someone point me at any samples of how you'd
go about serializing/deserializing a case class to/from json with
pinky?

Also, how do you unit test the http requests, is there an embedded
jetty or anything?

Basically, I just have a bare-bones myapp bootstrap and trying to hit
it from within a specs2 test. Any hints would be appreciated

Thanks

==================================================

class MyAppBootstrap extends PinkyServletContextListener {
modules = Array(
new CakeServletModule with CakeExampleServlet{
override def configureServlets {
val hello = new CakeExampleServletImpl
bindServlet(hello) toUrl ("/hello")
}
}
)
}

trait CakeExampleServlet {
import org.pinky.core.PinkySimpleServlet
import javax.servlet.http.{HttpServletResponse, HttpServletRequest}

class CakeExampleServletImpl extends PinkySimpleServlet {
GET {
(request: HttpServletRequest, response: HttpServletResponse) =>
"text/html" -> "hello World!"
}
// a simple post example
POST {
(request: HttpServletRequest, response: HttpServletResponse) =>
"text/html"-> "Hello World with POST"
}
}
}

==================================================

package com.sampleservice

import org.specs2.mutable.SpecificationWithJUnit
import org.specs2.execute.Result
import org.specs2.execute.Success

class SampleServiceSpec extends SpecificationWithJUnit {

"The Pinky Sample Service" should {
"execute json-based data roundtrip successfully" in {

Success("OK")

}
}

}


phausel

unread,
Oct 19, 2011, 3:09:42 PM10/19/11
to pinky-web...@googlegroups.com
Hi Dmitry,

1) regarding json serialization/deserialization:

2) regarding testing, please see this example using mockito:

HTH 
Thanks,
Peter

Dmitry G

unread,
Oct 20, 2011, 11:26:44 AM10/20/11
to pinky webframework
Thanks, Peter, will try those.

On Oct 19, 3:09 pm, phausel <peter.hau...@gmail.com> wrote:
> Hi Dmitry,
>
> 1) regarding json serialization/deserialization:
> I would probably usehttps://github.com/codahale/jerkson
>
> 2) regarding testing, please see this example using mockito:https://github.com/pk11/pinky/blob/master/src/test/scala/org/pinky/co...
>
> HTH
> Thanks,
> Peter
Reply all
Reply to author
Forward
0 new messages