I am using JAXB to serialize data to XML from java objects. I do not want to create some nodes if the xml is requested by unauthorized user.
Can this be done using JAXB?
Few non-JAXB solutions I can think of are:
- Remove nodes after generating XML with Regex or XSLT.
- Set the values of objects corresponding to the hidden nodes to null.
What will be the suggested approach?
Note: I’m the EclipseLink JAXB (MOXy) lead, and a member of the JAXB 2 (JSR-222) expert group.
Using any JAXB Implementation
You could use XSLT and leverage the
JAXBSourceobject as the input to the transformation.Using MOXy JAXB
If you are using the MOXy implementation of JAXB you could use its XML metadata to apply a second mapping to your object model.
Detailed Example