Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从JsonNode绑定play.data.Form时使用@JsonProperty映射属性_Json_Playframework 2.0 - Fatal编程技术网

从JsonNode绑定play.data.Form时使用@JsonProperty映射属性

从JsonNode绑定play.data.Form时使用@JsonProperty映射属性,json,playframework-2.0,Json,Playframework 2.0,我有以下课程 public static class Thing { @JsonProperty("_name_") String name; } 我试图将它绑定到表单,并以这种方式获取这个类的实例 ObjectNode node = Json.newObject(); node.put("_name_", "some name"); Form<Thing> thingForm = Form.form(Thing.class); thingForm = thing

我有以下课程

public static class Thing {
    @JsonProperty("_name_")
    String name;
}
我试图将它绑定到表单,并以这种方式获取这个类的实例

ObjectNode node = Json.newObject();
node.put("_name_", "some name");

Form<Thing> thingForm = Form.form(Thing.class);
thingForm = thingForm.bind(node);
Thing thing = thingForm.get();
ObjectNode节点=Json.newObject();
node.put(“_name”,“some name”);
Form thingForm=Form.Form(Thing.class);
thingForm=thingForm.bind(节点);
Thing=thingForm.get();
因此,我希望
thing.name
将是“某个名称”,但它不是,它是
null
。据我所知,
@JsonProperty
用于Json(反)序列化,如果可以的话,请尝试一下。问题是如何通过游戏的形式实现这一点

我还尝试按照docs中的描述调用它,但它的方法从未被调用


非常感谢您的帮助。

您是否尝试过使用
thingForm.bindFromRequest()
而不是
thingForm.bind()
?我使用了完全相同的东西,我用json数据制作了一篇ajax文章,它对我来说很好。它看起来与@JsonProperty()没有任何关系

你确定你想让类成为静态的吗?我假设您的表单属性具有公共getter/setter