views:

315

answers:

1

Hello!

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.

A: 

No, that behaviour is hard-wired. However, the required attribute is really a lightweight alternative to a proper XML schema. 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. The documents will then be checked on marshalling and unmarshalling, and you won't have to rely on the annotations for validation.

skaffman
Would you suggest that I first let JAXB generate a schema file, then modify it, and then let JAXB use that for validation?
ivan_ivanovich_ivanoff
Yeah, that's a good approach.
skaffman