O'Reilly logo

Play Framework Cookbook by Alexander Reelsen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Binding JSON and XML to objects

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.

Getting ready

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) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required