java - Stipulate that only one instance of an element is allowed in JAXB? -


i passing xml restful web service:

<root>     <element1/>         <element2/>     <element3/> </root> 

the web service unmarshal xml, , want ensure xml valid.

i used schema create java objects, , in schema element1 has maxoccurs=1 attribute has no effect on java objects created (unlike, example, adding minoccurs=1 result in "required=true" being added @xmlelement annotation). when unmarshalling xml passed web service, if element should appear once appears multiple times, last instance of element parsed. not want happen, want able alert client xml sent not valid , should remove whatever element not apply - not arbitrarily accept last element. believe involve little pre-validation before unmarshalling - , may able make use of beforeunmarshal method.

after doing bit of research, understanding there no jaxb annotation allow me specify element1 can exist once. case? possible validate @ without schema?

i have worked around issue allowing multiple instances of element in java object:

@xmlelement(name = "element1", required = true) private list<element1> element1; 

this allow me check size of list in afterunmarshal method, , if size of list greater 1, can throw new validationexception.


Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -