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
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-09-25 07:22 UTC by hinnerdal
Modified: 2015-04-07 12:49 UTC (History)
0 users

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

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
background: 
XmlElement annotation required=false is ignored if the field is a primitive


Example;

@XmlElement(required=false)
public int value;

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

Doing the same on Integer;

@XmlElement(required=false)
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.