• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

jaxb-api XML field missing does not trigger the DefaultValue

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using https://mvnrepository.com/artifact/jml/jaxb-api/2.1 .



then the Default Value of 'help2' is correctly set to 'false'. But if I do not send the field at all

then result of 'help2' is null, however I still want 'help2' to be the DefaultValue.

In essence I want jaxb to handle a missing 'help2' field equivalent to <help2/>.

So what to do?
 
Rancher
Posts: 4588
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As you've seen, JAXB won't do that for you if the element is missing entirely.

If you need a default value I suppose you could just assign it in the Java:


It does look a little odd, though.
 
Eric Jinson
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. The solution worked. I tried it earlier, but because of a Mixup in Project Versions in Maven, it failed.
 
He puts the "turd" in "saturday". Speaking of which, have you smelled this tiny ad?
Try Free Java/.NET Libraries for Word Excel PowerPoint and PDF
htttp://www.e-iceblue.com/free-apis.html
    Bookmark Topic Watch Topic
  • New Topic