This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 247464 - Add hint: @XmlElement(required=false) is useless on primitives
Summary: Add hint: @XmlElement(required=false) is useless on primitives
Status: NEW
Alias: None
Product: xml
Classification: Unclassified
Component: JAXB (show other bugs)
Version: 8.1
Hardware: All All
: P3 normal (vote)
Assignee: Svata Dedic
Depends on:
Reported: 2014-09-25 07:22 UTC by hinnerdal
Modified: 2015-04-07 12:49 UTC (History)
0 users

See Also:
Exception Reporter:


Note You need to log in before you can comment on or make changes to this bug.
Description hinnerdal 2014-09-25 07:22:54 UTC
XmlElement annotation required=false is ignored if the field is a primitive


public int value;

this is exposed as
<xs:element name="value" type="xs:int"/>

Doing the same on Integer;

public Integer value;

<xs:element name="value" type="xs:int" minOccurs="0"/>

There should have been a warning, or hint to rewrite the int primitive to Integer in this case, because the annotation does not what the user may expect.

I have been bitten by this twice now, since I forgot this rule, and I needed to add some functionality in a webservice that should be backward compatible to existing clients, thus I need to add a field that is not required (minOccurs="0") and clients broke horribly when adding this as a primitive, and I thought the annotation would work.