• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JAXB: how to configure the format of numbers and dates dynamically.

 
Ranch Hand
Posts: 157
Netbeans IDE Postgres Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello:

I'm new to use JAXB. I'm using it through JAX-RS. I want to know if it's possible to configure either of them dynamically, to change the format of the numbers and dates during the marshalling and unmarshalling operations. I've searched and have found that you can extend the class javax.xml.bind.annotation.adapters.XmlAdapter to create your own adapter, and then use it as the value attribute of the javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter annotation. Then, you only have to use the annotation with the field that you want to format. But I need that this configuration can be done in real time, because the format depends on the locale indicated by the client that calls the Web service.

If I'm not mistaken, when you use the XmlJavaTypeAdapter annotation, you've not control about when and how the adapter is instantiated, so I guess that this solution won't work in this case. Am I right?

I've also read that you can use a mapping file, called bindings.xml. But it isn't a solution either, because it's also defined statically, like the annotations. So, Is it possible to do such thing with JAXB?

Thank you.
 
reply
    Bookmark Topic Watch Topic
  • New Topic