XML : Using @Nonnull with JAXB

I'm using @NonNull for a JAXB'd xml object, simplified example below:

  Public class MyXML  {      @Nonnull      public Double myNumber;        public MyXML() { }  //Required for JAXB  }    

However, my IDE (Eclipse) displays the following warning on the constructor:

The @NonNull field myNumber may not have been initialized

Which makes sense as it stands.

How can I make use of @Nonnull (which is very useful) alongside JAXB without this warning appearing?

I don't want to just @surpress it away.
I can't give the myNumber a default value, as it shouldn't have one. I'd like it to throw an exception rather than create the object. I can't validate myNumber in the constructor, as it's already too late by this point.

All advice appreciated!

Greg

No comments:

Post a Comment