JAXB required = true似乎不需要 [英] JAXB required=true doesn't seem to require

查看:136
本文介绍了JAXB required = true似乎不需要的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有这个JAXB注释:

We have this JAXB annotation:

 @XmlElement(name = "Strategy", required = true)
 protected List<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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆