0

I am using Betwixt to output XML from a Java class, using .betwixt files to configure the mapping.

I am required to output some XML like this ( I have to conform to a third party DTD:

<data>
   <Status>Active</Status>
   <StatusCount>3</StatusCount>
   <Status>InActive</Status>
   <StatusCount>5</StatusCount>
   <Status>Banned</Status>
   <StatusCount>1</StatusCount>
</data>

My class has a method which returns a list of StatusCount objects

List<StatusCount> getStatusCounts() {

My StatusCount Object has:

String getStatusName() { ... }
String getStatusCount() { ... }

I can't work out the betwixt config to get the output I want. I get an extra element wrapping each pair of Status/StatusCount nodes, which I don't want.

Is it possible not to have this element? Thanks for any help!

anorakgirl
  • 668
  • 8
  • 19

1 Answers1

0

I don't think that specific format is possible, i.e. you can't guarantee Status and StatusCount come one after the other.

You can, however, construct a class that binds the XML representation and your StatusCount object where it has two lists of String like:

public class StatusCountProxy {
    private List<String> statusName = new ArrayList<String>();
    private List<String> statusCount = new ArrayList<String>();
}

From these strings you can build your pairs. This should make it possible to deserialize the given xml with betwixt. For serialization to the same format you need to hack a little where you must create a Status object and a StatusCount object, then write them out in pairs.

Jes
  • 2,748
  • 18
  • 22