0
votes

I have a pretty large set of Java classes, many that stem from each other. I want to know how to specify in the java code (with an annotation) when a certain property of a class is limited. For example, a vehicle.java class should only be able to have 1 manufacturer and 2-4 wheels.

I have come across minOccurs and maxOccurs in generated XML schemas, but I'm not sure what anootations in java code caused these to appear.

I tried putting @XmlElement(name"manufacturer", minOccurs="0") in my java code in the Car class, but minOccurs throws an error.

Thanks.

1
and where do you want the limitation to be enforced? When serializing/deserializing to/from XML, or also when the class is used by other classes?matt b
I need to put the minOccurs/maxOccurs annotations in the Java code so when converted to XML it appears thereDan
So, no unicycles (1 wheel), hovercraft (0 wheels) or trucks (18 wheels)?Donal Fellows

1 Answers

0
votes

Try @XMLElement(required=false) which should give you a minOccurs of 0