Hi Thomas,

Thomas Fuller wrote:

> Hi Jörg,
> 
> Re "This should make it immediately obvious, why the value of your
> deserialized IncomeLevel instances is null."
> 
> Maybe to you but I'm still missing it. Note that the deserialized
> IncomeLevel instances is not actually null. The class is created, the id
> is set correctly -- it's the value which is null.

For sure, because in your XML the wb:incomeLevel does not have an inner 
element with the tag "value". That's how you have configured the XStream -- 
clearly visible when you create the XML from the objects. That XML element 
is not optional, it is expected. Any text of the eb:incomeLevel element is 
unexpected and therefore simply ignored.

> If I move the converter and the value property to the IncomeLevel and
> likewise remove the converter and value property from the IdValuePair,
> then the XML that is serialized appears to be correct (I've pasted the
> classes below) -- however this is not where I want this to be.

This is your problem -- you do *not* have a choice where you define the 
converter. Each instance of the ToAttributedValueConverter will handle only 
one class and that is exactly the one it was registered for. However, you do 
not have to move the value property:

================== %< =================
@XStreamConverter(value=ToAttributedValueConverter.class, strings={"value"}, 
types={IdValuePair.class})
public class IncomeLevel extends IdValuePair {
 // ...
}
================== %< =================

For more convenience, simply derive your own converter:

================== %< =================
public class ValuedConverter extends ToAttributedValueConverter {
  public ValuedConverter(final Class type, final Mapper mapper, final 
ReflectionProvider reflectionProvider, final ConverterLookup lookup) {
    super(type, mapper, reflectionProvider, lookup, "value", 
IdValuePair.class);
  }
}

@XStreamConverter(ValuedConverter)
public class IncomeLevel extends IdValuePair {
 // ...
}
================== %< =================

Cheers,
Jörg


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

    http://xircles.codehaus.org/manage_email


Reply via email to