Re: [Simple-support] Read text or elements for the same element tag
Brought to you by:
niallg
|
From: Nugroho S. <nug...@gm...> - 2012-02-16 05:51:53
|
Please ignore my previous email. I just read the Javadoc and found @Convert
can be applied to class level.
Thank you.
Regards,
Nugroho
On Thu, Feb 16, 2012 at 12:44 PM, Nugroho Saputro <nug...@gm...
> wrote:
> Hi Niall,
>
> In which part I should use @Converter? In my case, I don't have @Element
> annotation.
>
> Can @Converter be applied to @ElementList ?
>
> Thank you.
>
> Regards,
> Nugroho
>
>
> On Wed, Feb 15, 2012 at 4:09 PM, Niall Gallagher <
> gal...@ya...> wrote:
>
>> You will have to use a Converter, @Text can not be used with any element
>> annotation.
>>
>> --- On *Tue, 14/2/12, Nugroho Saputro <nug...@gm...>* wrote:
>>
>>
>> From: Nugroho Saputro <nug...@gm...>
>> Subject: [Simple-support] Read text or elements for the same element tag
>> To: sim...@li...
>> Received: Tuesday, 14 February, 2012, 10:24 PM
>>
>>
>> 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
>>
>>
>>
|