Skip to main content

minoccur on xsd:int

5 replies [Last post]
tprscott
Offline
Joined: 2008-02-06

I have been trying to annotate something like this.

@XmlElement(defaultValue="helloTest")
private String foo = "hello";

@XmlElement(defaultValue="-1")
private int val = -1;

When I run the schemageneration on this I notice that for the foo element it will create a minoccurs like so.

I have also noticed that the int does not have a minOccurs value on it.

Is there a way to get a minOccurs to generate on the int field?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
SaumyaK
Offline
Joined: 2012-11-29

I have another query over this. I was facing same issue, then as you have mentioned the workaround of adding the "type" for primitive types, I have tried the same. It resolved the issue and I started getting another problem, maxOccurs="unbounded" is now not coming for Array fields. When I remove "type=Wrapper.class" (Integer for int), I am getting maxOccurs="unbounded" for arrays, but this is again giving problem for 'minOccurs=0' for fields which are not marked "required=true".

Can someone please help?

tprscott
Offline
Joined: 2008-02-06

I believe I have found a work around.

@XmlElement(type=Integer.class)
private int val = -1;

If you do this you will get a minOccurs=0 when you generate the xml. I guess I just need someone to explain why I have to use Integer and why I can't just use a primitive type here. I am sure it is just my lack of understanding...

bhaktimehta
Offline
Joined: 2004-03-18

Try @XmlElement(required=false ) the javadoc says it should generate minOccurs=0
Regards,
Bhakti

tprscott
Offline
Joined: 2008-02-06

Thanks for the response. Yeah I tried that even though it appears that required is defaulted to false. Either way that didn't help my situation. Do you have any other ides?

tprscott
Offline
Joined: 2008-02-06

It seems that I can't get the minoccur to appear on any simple type not just int. What I want to do is make an element optional because it has a default value. I looked at the defaultValue option of the @XmlElement annotation but that seems to require you to still have the tag like this:


testing

What I want is the ability to pass xml like so and have it create my class.


testing