Question

I try to serialize this class using the simple XML framework :

public class Div
{
  private MyFrameworkList< Div > _children = new MyFrameworkList< Div >() {{
    append( new Div( "a" ) );;
    append( new Div( "b" ) );;
    append( new Div( "c" ) );;
  }};

  // some methods and attributes...
}

To :

<div>
  <children>
    <div class="a">
    </div>
    <div class="b">
    </div>
    <div class="c">
    </div>
  </children>
</div>

MyFrameworkList is part of a framework and it doesn't implement Collection interface so it can't be annotated @ElementList. Unfortunately I can't fix the last point.

I tried to build a Converter but I don't find how to serialize list values.

Thanks

Was it helpful?

Solution

There are some ways to do this:

Implement a Converter for ...

  1. Div class, so you can create the serialization of this class by your own - allowing you to fully customize your xml.
  2. _children field only, so you can do the same as 1., but only for this single field - everything else is done default by simple.
  3. MyFrameworkList class - similar to 2., but annotated for the class, so other instances everywhere around your code get serialized that way too.

I've already answered your other question, there you'll find an example of how to implement and use Converters in simple; please see here.

If you get stuck at any place, please report back and we'll fix your problem ;-)

OTHER TIPS

You could iterate over the list and create a String representation, similar to what we do with toString

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top