#17 inline for Element

open
nobody
None
5
2011-04-19
2011-04-19
Anonymous
No

Fairly often there is a need to "flatten" the generated xml in the sense that you have several Java objects contained in one Java object which should generate a flat xml structure. They should be serialized into the same element due to the structure of the required xml protocol. This is exactly the functionality that is already provided for ElementList.

Example:
public class Message {
@Element(inline=true)
private Header myHeader;
@Element(inline=true)
private Product myProduct;
}

which should be serialized into a structure like
<message>
<sender>a</sender>
<timestamp>1</timestamp>
<productid>2</productid>
</message>

We assume that sender and timestamp reside in the Header object and the productid in the Product object.

Since this makes deserialization a bit trickier as a first step it could be made available for serialization only. The API seems to be pretty prepared for this change already.

It could be argued that a Converter should be used but that pretty much removes the idea of having Simple in the first place, you might as well build the xml in a StringBuffer in that case. In this particular case the Product is also a large number of subclasses meaning that there would have to be a Converter per subclass.

Maybe there is already some sneaky way to achieve this funtionality but I have not been able to figure it out.

Discussion