1

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 record 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.

Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588

3 Answers3

2

As Merlyn Morgan-Graham said as a comment to your question, You can aggregate them into a separate class, and serialize that one.

Community
  • 1
  • 1
Adeel Ansari
  • 39,541
  • 12
  • 93
  • 133
0

How about composition. A Pojo class contains other pojo's objects as xml entity.

Talha Ahmed Khan
  • 15,043
  • 10
  • 42
  • 49
0

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.

Andreas Dolk
  • 113,398
  • 19
  • 180
  • 268