I am using JAXB to save my objects to XML. I have one problem with this though: One of my classes has a String
myclass.getFilePath() // returns an absolute file path
which represents an absolute file path. Before writing this file path to an XML file, I want to relativize it, so I need some kind of preprocessing on my getter. Is that possible using JAXB?
I know I could modify my class and add getRelativePath()
and setBasePath()
but I would prefer to somehow transform my file path and only do this when exporting to XML.
Update:
@XmlJavaTypeAdapter(MyConverter.class)
should be close to the solution, though I still need a way to pass in an argument (the base path for the relative path) - any hint on this?
Update 2
Probably this does the job: Anyway to pass a constructor parameter to a JAXB Adapter? Will check it now.