1

我们有一个基于 jaxws 的 web 服务,它使用 JAXB pojos 来定义模型。生成 WSDL。这些 pojo 已经包含验证信息等@XmlElement(nillable=false)。有没有办法以编程方式验证这些 pojo,例如在单元测试中?

@XmlRootElement
public class Person
    private String name;

    @XmlSchemaType(name="string")
    @XmlElement(required=true,nillable=false)
    public String getName() {
        return name;
    }
}

@Test
public void nameIsSet() {
    Person p = new Person();
    // Howto validate p so that it matches the constraints?
}

这个想法是重用 pojo 进行编程创建和操作(而不是通过 XML),而不必添加 bean 验证注释:

    @XmlSchemaType(name="string")
    @XmlElement(required=true,nillable=false)
    @NotNull // I don't want to add this
    public String getName() {
        return name;
    }
4

0 回答 0