Can you optionally serialize a class property through JAXB?

You could do this by applying multiple mappings to your object model. Standard JAXB only allows you to have one mapping applied through annotations. Other JAXB implementations such as MOXy (I lead this implementation), also allow you to represent metadata as XML.

Up vote 1 down vote favorite 1 share g+ share fb share tw.

E.g. Suppose I Have @XmlRootElement public class TodoItem { private int id; private String title; private String note; // getters, setters } and the following web service operatios: public TodoItem getTodoItemFull(int id) { .... } public TodoItem getTodoItemMinimal(int id) { .... } Is there a special annotation I can use so that I can decide at runtime whether property "note" will be serialized? In other words, the getTodoItemFull() method will return the fully serialized class, while the getTodoItemMinimal() method will return that serialized class without the "note" xml element?

Thanks,! Java xml serialization jaxb jax-ws link|improve this question asked Aug 25 '10 at 19:26wsb33838251120 70% accept rate.

You could do this by applying multiple mappings to your object model. Standard JAXB only allows you to have one mapping applied through annotations. Other JAXB implementations such as MOXy (I lead this implementation), also allow you to represent metadata as XML: wiki.eclipse.org/EclipseLink/Examples/MO... You could have one JAXBContext built on one set of metadata that fully mapped the object model that the "getTodoItemFull" would use, and another JAXBContext built on another set of metadata that partially mapped the object model that getTodoItemMininmal would use.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions