After you have explored Play a little bit and written your first apps, you might have noticed that it works excellently when binding complex Java objects out of request parameters, as you can put complex objects as controller method parameters. This type of post request deserialization is the default in Play. This recipe shows how to convert JSON and XML data into objects without changing any of your controller code.
The source code of the example is available at examples/chapter4/mashup-json-xml
.
Let's start with a controller, which will not change and does not yield any surprises, as shown in the following code snippet:
public class Application extends Controller { public static void thing(Thing thing) { renderText("foo:"+thing.foo+"|bar:"+thing.bar+"\n"); } }
You should add a correct route for the controller as well in conf/routes
POST /thing Application.thing
Start with a test as usual:
public class ApplicationTest extends FunctionalTest...