Skip to content

Instantly share code, notes, and snippets.

@Peksa
Created January 5, 2012 22:12
Show Gist options
  • Save Peksa/1567606 to your computer and use it in GitHub Desktop.
Save Peksa/1567606 to your computer and use it in GitHub Desktop.
Custom JSON Binder
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