[英]JAXB: Can I make XmlAttribute's parameter “required=true” to default?
I have 我有
@XmlAttribute(required=true)
in hundreds places in a projects. 在一个项目的数百个地方。
Can I make this default? 我可以将此设置为默认值吗? ... ...
...So that I then only need to specify ...这样我只需要指定
@XmlAttribute(required=false)
when needed. 需要的时候。
No, that behaviour is hard-wired. 不,这种行为是硬连线的。 However, the required
attribute is really a lightweight alternative to a proper XML schema. 但是, required
属性实际上是适当XML模式的轻型替代方案。 If you need better control over document validation, then I suggest you define an XML Schema for your documents, and inject the schema into the JAXBContext
. 如果您需要更好地控制文档验证,那么建议您为文档定义XML Schema,并将该模式注入JAXBContext
。 The documents will then be checked on marshalling and unmarshalling, and you won't have to rely on the annotations for validation. 然后,将对文档进行编组和拆组进行检查,并且您不必依赖注释进行验证。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.