Play框架中的表单验证
问题描述:
我正在用Java中的Play 2.3创建一个Play应用程序.
I am creating a Play application with Play 2.3 in Java.
我正在尝试使用Form处理带有JSON正文的POST请求.
I'm trying to use Form for handling POST request with JSON body.
我的问题是,如果我的JSON是仅具有Strings或Floats属性的简单对象,则它会很好地工作.但是,如果我放一些对象约束,它将继续牢固地绑定请求,但不对嵌套对象进行约束验证.
My problem is that if my JSON is a simple object with only Strings or Floats attribute, it works well. But if I put some of Object imbrication, it continue to bind the request corectly but don't do the Constraints validation in nested objects.
以下是我要执行的操作的一个示例:
Here an exemple of what I'm trying to do :
public class PairRequest
{
@Required
public String epc;
@Required
public RequestProduct product;
}
public class RequestProduct
{
//Product data
@Constraints.Required
private String productCode;
@Constraints.Required
public Brand brand;
@Constraints.Required
private String furniture;
}
@Entity
public class Brand extends Model {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Long id;
@Column(length = 250)
@Constraints.Required
public String name;
@Column(nullable = true, length = 512)
public String regex;
}
我错过了什么吗?这很奇怪,因为我认为它是第一次运行.但是我不确定.
Have I missed something ? It's weird because I think it was working during first times... But I can't be sure.