我正在使用play框架,我想为来自POST方法的JSON创建一个自定义绑定器.我试图用@Global TypeBinder做到这一点,但这似乎只适用于事情来自表单编码(我正在挖掘Binder.java并且似乎没有考虑POST主体进行绑定并假设有用于数据的参数中的名称前缀).
现在我采取这里引用的方法似乎已经过时了,所以我假设事情已经发生了变化.
public class GsonBinder implements TypeBinder<JsonObject> {
public Object bind(String name, Annotation[] antns, String value, Class type) throws Exception {
return new JsonParser().parse(value);
}
}
Run Code Online (Sandbox Code Playgroud)