Is it possible to marshall all pojo (of same type) in a single xml using o/x mappers? like I want to generate the following xml file
<xml>
<record1>
<id>1</id>
<name>abc</name>
</record1>
<record2>
<id>2</id>
<name>xyz</name>
</record2>
</xml>
here record1 and reco开发者_开发技巧rd 2 are same type of objects.Means I want to write first record1 object in xml file than record2 object in that same xml file.
As Merlyn Morgan-Graham said as a comment to your question, You can aggregate them into a separate class, and serialize that one.
How about composition. A Pojo class contains other pojo's objects as xml entity.
Spring documentation clearly says:
Within the field of O/X mapping, a marshaller is responsible for serializing an object (graph) to XML.
So the direct answer is no. We marshal one object to one xml document. If you need more then one instance in a single document, you'll have to implement some sort of wrapper class. A class containing a simple collection (a list or a set) which stores your marshallables and providing some get/add methods should be sufficient.
精彩评论