posted 8 years ago
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.