从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