[Simple-support] Read text or elements for the same element tag
Brought to you by:
niallg
|
From: Nugroho S. <nug...@gm...> - 2012-02-15 06:25:12
|
Hi,
I have the following XML. custom_field element can contains a Text or a set
of elements.
<record>
<custom_field id="2">
*Value 1*
</custom_field>
<custom_field id="2">
* <option selected="true">option 1</option>*
* <option>option 2</option>*
</custom_field>
</record>
I tried the following annotation
@Root(name="record", strict=false)
public class Record {
@ElementList(entry="custom_field", inline=true, required=false)
public List<CustomField> customFields = new ArrayList<CustomField>();
}
------------
@Root(name="custom_field", strict=false)
public class CustomField {
@Text(required=false)
public String value; // single value
@ElementList(inline=true, entry="option", required=false)
public List<FieldOption> options = new ArrayList<FieldOption>(); //
options value
}
I get this error :
Unable to read XML. Text annotation
@org.simpleframework.xml.Text(data=false, empty=, required=false) on field
'value' public java.lang.String com.test.CustomField.value used with
elements in class com.test.CustomField
Any idea to solve this problem?
I wonder if I can use converter but where should I put it as I don't use
@Element here.
Thank you.
Reagrds,
Nugroho
|