Skip to content

Instantly share code, notes, and snippets.

@guillaumebort
Created December 6, 2010 11:29
Show Gist options
  • Save guillaumebort/730163 to your computer and use it in GitHub Desktop.
Save guillaumebort/730163 to your computer and use it in GitHub Desktop.
package controllers;
import play.mvc.*;
import com.google.gson.*;
import models.*;
public class Application extends Controller {
public static void handleJson(JsonObject body) {
renderText(body.getAsJsonPrimitive("name").getAsString());
}
public static void handleJsonAsObject(JsonObject body) {
User u = new Gson().fromJson(body, User.class);
renderText(u);
}
}
package utils;
import java.lang.annotation.*;
import com.google.gson.*;
import play.data.binding.*;
@Global
public class GsonBinder implements TypeBinder<JsonObject> {
public Object bind(String name, Annotation[] antns, String value, Class type) throws Exception {
return new JsonParser().parse(value);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment