Re: [Simple-support] help with deserializing XML to ElementMap
Brought to you by:
niallg
|
From: Micah J. <mi...@af...> - 2008-02-25 22:25:07
|
Hi,
Thanks for the response, but as you can see in the XML, the
particular attribute it's complaining about (attribute "id" in
element "field") is in fact there. Any other thoughts?
-Micah
On Feb 25, 2008, at 2:01 PM, Niall Gallagher wrote:
> Hi,
>
> Required means it can not be null, if it is not
> required and null it won't appear. So you must provide
> a value for required attributes.
>
> Niall
>
>
> --- Micah Jaffe <mi...@af...> wrote:
>
>> I'm trying to convert some existing XML parsing code
>> to use Simple
>> XML and am almost there, but I'm running into an
>> issue trying to use
>> ElementMap.
>>
>> Here's the XML (abbreviated):
>>
>> <?xml version="1.0" encoding="ISO-8859-1"?>
>> <index id="users">
>> <database>xyz</database>
>> <query>
>> <columns>foo,bar</columns>
>> <tables>a,b,c</tables>
>> </query>
>> <fields>
>> <field id="foo">
>> <lucene>
>> <index>TOKENIZED</index>
>> <store>false</store>
>> <default>true</default>
>> </lucene>
>> </field>
>> <field id="bar">
>> <lucene>
>> <index>TOKENIZED</index>
>> <store>false</store>
>> <default>true</default>
>> </lucene>
>> </field>
>> </fields>
>> </index>
>>
>> Here are my classes:
>>
>> @Root(name="index")
>> public class IndexConfig {
>>
>> @Attribute
>> private String id;
>>
>> @Element
>> private String database;
>>
>> @Element
>> private Query query;
>>
>> @ElementMap(name="fields", entry="field",
>> key="id",
>> attribute=true, keyType=String.class,
>> valueType=Field.class)
>> private HashMap<String, Field> fields = new
>> HashMap<String,
>> Field>();
>> }
>>
>> @Root
>> public class Field {
>>
>> @Attribute
>> private String id;
>>
>> @Element
>> private Lucene lucene;
>> }
>>
>> [Not including Query or Lucene classes here as
>> they're not at issue]
>>
>> The parsing chokes here:
>>
>> org.simpleframework.xml.load.ValueRequiredException:
>> Unable to
>> satisfy @org.simpleframework.xml.Attribute(name=,
>> empty=,
>> required=true) on field 'id' for class
>> com.affinitycircles.core.xml.Field at line 16
>> at
>> org.simpleframework.xml.load.Composite.validate
>> (Composite.java:389)
>> at
>>
> org.simpleframework.xml.load.Composite.readAttributes
>>
>> (Composite.java:221)
>> at
>> org.simpleframework.xml.load.Composite.read
>> (Composite.java:193)
>> [... the rest deleted ...]
>>
>> For some reason it can't seem to find the id
>> attribute for Field. If
>> I make the id attribute optional, then it seems the
>> parser gets
>> confused and is looking for elements in the Lucene
>> block. If I
>> change ElementMap to instead be an ElementList, the
>> file will parse.
>> I've tried not using @Root with Field and that
>> doesn't affect the
>> outcome (I'm really not sure what @Root is for...).
>>
>> Any help?
>>
>> -Micah
>>
>>
> ----------------------------------------------------------------------
> ---
>> This SF.net email is sponsored by: Microsoft
>> Defy all challenges. Microsoft(R) Visual Studio
>> 2008.
>>
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
>> _______________________________________________
>> Simple-support mailing list
>> Sim...@li...
>>
> https://lists.sourceforge.net/lists/listinfo/simple-support
>>
>
>
>
>
> ______________________________________________________________________
> ______________
> Looking for last minute shopping deals?
> Find them fast with Yahoo! Search. http://tools.search.yahoo.com/
> newsearch/category.php?category=shopping
|