Created
January 5, 2012 22:12
-
-
Save Peksa/1567606 to your computer and use it in GitHub Desktop.
Custom JSON Binder
This file contains hidden or 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 misc; | |
import play.*; | |
import play.mvc.*; | |
import com.google.gson.*; | |
import java.util.*; | |
import java.lang.reflect.*; | |
import java.lang.annotation.*; | |
public class BinderPlugin extends PlayPlugin | |
{ | |
public Object bind(String name, Class clazz, Type type, Annotation[] annotations, Map<String, String[]> params) | |
{ | |
if (Http.Request.current().contentType.equals("application/json")) | |
{ | |
if (name.equals("json")) | |
{ | |
return new Gson().fromJson(Scope.Params.current().get("body"), clazz); | |
} | |
} | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment