JAXB required=true 似乎不需要 [英] JAXB required=true doesn't seem to require
本文介绍了JAXB required=true 似乎不需要的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们有这个 JAXB 注释:
We have this JAXB annotation:
@XmlElement(name = "Strategy", required = true)
protected List<Strategy> strategy;
如果不存在 Strategy
元素,则不会抛出异常..这是为什么?我们不应该得到一个例外吗?
If there are no Strategy
elements present, no exception is thrown.. why is this? Shouldn't we get an exception?
推荐答案
JAXB 参考实现不使用此属性进行验证,它纯粹用于文档目的.
The JAXB reference implementation doesn't use this attribute for validation, it's purely there for documentation purposes.
如果你需要验证文档,你需要定义一个XML Schema,并将其注入到Marshaller
或Unmarshaller
中,使用SchemaFactory
.
If you need to validate the documents, you need to define an XML Schema, and inject it into the Marshaller
or Unmarshaller
, using SchemaFactory
.
这篇关于JAXB required=true 似乎不需要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文