Created
December 6, 2010 11:29
-
-
Save guillaumebort/730163 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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