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?
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?
The JAXB reference implementation doesn't use this attribute for validation, it's purely there for documentation purposes.
If you need to validate the documents, you need to define an XML Schema, and inject it into the Marshaller
or Unmarshaller
, using SchemaFactory
.
As written above true validation is only done from a schema.
If you wish to first create your class and still enjoy schema validation without writing your schema to disk you can create it from the class at run-time and use it for validating when you unmarshal here is an example: