Hi Geoffrey,

Geoffrey De Smet wrote:

> My model looks like this:
> 
> class Table {
>    List<Row> rows;
>    List<Column> columns;
>    List<Cell> cells;
> }
> class Row {
>     List<Cell> cells;
> }
> class Column {
>     List<Cell> cells;
> }
> class Cell {
>    Row row;
>    Column column;
> }
> 
> 
> When I xstream this to XML with ID_REFERENCE, I get something ugly like
> this:
> 
> <table>
>     <!-- rows -->
>     <row id="1"><!-- row 1 -->
>        <cell id="2">
>           <row ref="1">
>           <column id="3">
>              <cell ref="2"/>
>              <cell id="4">
>                  <row id="5"> <!-- row 2 -->
>                     ... <!-- VERY DEEP INDENTATION, up to depth cellSize
>                     -->
>                         <!-- All cells get initialized here !!! -->
>                  </row>
>                  <column ref="3"/>
>               </cell>
>               <cell ref="..."/>
>               ...
>            </column>
>       <cell ref="..."/>
>       ...
>     </row>
>     <row ref="5"/>
>     ... (other rows, refs only)
> 
>     <!-- columns -->
>     <column ref="3"/>
>     <column ref=""/>
>     ... (other columns, also refs only)
> 
>     <!-- cells -->
>     <cell ref="2"/>
>     ... (other cells, also refs only)
> <table/>
> 
> 
> The indentation of that beast is ugly
> and it scales poorly in memory & disk space.
> How do I avoid that (without removing the bi-directional relationships
> in my classes)?
> Preferably, I 'd like it to write all rows, first, then all columns and
> then all cells.

Actually you cannot, at least you will not have any help from XStream. 
XStream's model is stream based, i.e. it will not create any forward 
references nor can such references be resolved at deserialization, because 
the referenced object is simply not known.

You will have to break the relationship - at least for XStream, i.e. make 
the element (list ?) in the row transient and at deserializaiton time add 
the cell to the referenced row in the cell converter.

Cheers,
Jörg


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to