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.

Revisions

  1. Peksa revised this gist Jan 29, 2012. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions BinderPlugin.java
    Original file line number Diff line number Diff line change
    @@ -16,8 +16,7 @@ public Object bind(String name, Class clazz, Type type, Annotation[] annotations
    {
    if (name.equals("json"))
    {
    JsonObject json = new JsonParser().parse(Scope.Params.current().get("body")).getAsJsonObject();
    return new Gson().fromJson(json, clazz);
    return new Gson().fromJson(Scope.Params.current().get("body"), clazz);
    }
    }
    return null;
  2. Peksa created this gist Jan 5, 2012.
    25 changes: 25 additions & 0 deletions BinderPlugin.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    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"))
    {
    JsonObject json = new JsonParser().parse(Scope.Params.current().get("body")).getAsJsonObject();
    return new Gson().fromJson(json, clazz);
    }
    }
    return null;
    }
    }