Skip to content

Instantly share code, notes, and snippets.

@fahied
Forked from guillaumebort/Application.java
Created February 15, 2012 10:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fahied/1834970 to your computer and use it in GitHub Desktop.
Save fahied/1834970 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