I want to selectively serialize fields based on the request and the user.
For example, an admin user would be served an XML with some additional fields. Whereas a normal user would get an XML without those fields.
Secondly, at present I use @XmlIDREF
to prevent unnecessary expansion of referenced objects or collections.
But sometimes the user might want those details. Making a second request for the referenced object is not be desirable. I want to let the user tell the server that XYZ attribute should be expanded (i.e. include the complete object and not just its reference)
Given a user and a request, based on business logic I can tell which fields should be serialized. Now how do I communicate this information to JAXB?
As far as possible, I do not want to create an XSD. Note that request parameters are dynamic. Which fields to serialize is decided at run-time. So I cannot use something that has to be hard coded - like @Transient
or @XmlIDREF
annotations.