I entered issue #1313 with my description of the problem and my workaround.  I did not include a patch, because I don't think my workaround is a valid contribution to the codebase, but my description of the workaround will hopefully give clues to the underlying problem. I did not attach a test case to this initial report, because I have to figure out how to create one first.

Bryan

Werner Guttmann <[EMAIL PROTECTED]> wrote:
Bryan,

can you please open a Jira issue at
http://jira.codehaus.org/browse/CASTOR, attach the content of your
emails (as a minimum), and we are going to have a close look .. ;-).

Having said that, if you could attach a unified patch that included a
(initially non-)working sample, the code changes required, this would be
a great help to all of us.

Thanks
Werner

Bryan Helm wrote:
> I have confirmed that the XMLFieldDescriptor used during unmarshalling
> the value field does not match the XMLFieldDescriptor created for the
> field while loading the mapping file. To workaround this, I had to add a
> hack to UnmarshalHandler to set multivalued true if the field type is a
> Collection. In UnmarshalHandler.endElement, after the descripor is
> verified (around line 729), I added this:
>
> /****** HACK! HACK! HACK! *************/
> // I cannot get Castor to handle List values in a HashMap.
> // I added support for a MapCollectionItem similar to MapItem, but
> // the XLFieldDescriptor has _multivalued false when it should
> be true.
> // I could not figure out why, so I override it here.
> if( ! descriptor.isMultivalued() ) {
> if( descriptor instanceof XMLFieldDescriptorImpl ) {
> if( ((XMLFieldDescriptorImpl)descriptor).getFieldType()
> == Collection.class ) {
>
> ((XMLFieldDescriptorImpl)descriptor).setMultivalued(true);
> }
> }
> }
> /****** end HACK! HACK! HACK! *************/
>
> This, along with my changes adding support for MapCollectionItem, allows
> a HashMap with List values to be unmarshalled.
>
> Bryan
>
> */Bryan Helm <[EMAIL PROTECTED]>/* wrote:
>
> I have been trying a workaround where I defined a MapCollectionItem
> class that has Collection for the return type of the getter and
> argument type of the setter. Every where I saw MapItem being
> referered to, I added checks for argument type being Collection, and
> used MapCollectionItem instead. This is marshalling correctly with
> the xsi:type set to my new class. However, the unmarshal still
> fails with "element "value" occurs more than once.". I have tracked
> that problem down to being an issue with the _multivalued flag of
> the XMLFieldDescriptor for the "value" field. When loading the
> mapping file, I see the XMLFieldDescriptor correctly set with
> _multivalued = true. However, during unmarshal, the field descriptor
> being looked at for that field has _multivalued = false. I don't
> know if the flag is being changed somewhere, or if a different field
> descriptor is being used. If I set that flag to true in the
> debugger, then the unmarshal works.
>
> Bryan
>
> */Stephen Bash <[EMAIL PROTECTED]>/* wrote:
>
> Bryan-
>
> I've never done a List inside a Map before, but I have done a Map
> inside a Map. In that case I had to use:
>
>
> collection="hashtable">
>
> That being said, I do remember having to use hashtable rather
> than map
> for the inner map, so there might be some funny interactions
> going on
> between nested class mappings and the collections API. If I were
> you,
> I might try setting the type to MapItem and see if that changes
> anything... But I'm really shooting in the dark.
>
> If I get a chance, I'll dig into it a little. Let me know if you
> find
> anything out.
>
> Stephen
>
>
> On 1/31/06, Bryan Helm wrote:
> >
> > I am trying to use Castor 0.9.9.1-xml to unmarshall a HashMap
> that has a List as the value. I was not able to find an answer
> searching the archives (although I saw the question asked for a
> LinkedList, but not answered). If I specify a collection
> attribute for the field description for the value field of the
> nested MapItem class, I get this error when the mapping is
> loaded into the unmarshaller:
> >
> > The return type for method public java.lang.Object
> org.exolab.castor.mapping.MapItem.getValue() does not match the
> declared field type java.util.Collection
> >
> > I have no idea why Collection does not match Object, or how to
> workaround this. If I do not specify the collection attribute
> (or, curiously, if I use collection="arraylist" instead of
> collection="collection"), I get this error during unmarshalling,
> when the second element of the list is encountered:
> >
> > element "value" occurs more than once.
> >
> > My mapping file looks something like this:
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > XML looks something like this:
> >
> >
> >
> > key
> >
> >
> >
> >
> >
> > Is there a known way to map a Map that has Collection values?
> >
> > Bryan
> >
> >
> >
> > ________________________________
> Do you Yahoo!?
> > With a free 1 GB, there's more in store with Yahoo! Mail.
> >
> >
>
>
> ------------------------------------------------------------------------
> Do you Yahoo!?
> With a free 1 GB, there's more in store with Yahoo! Mail.
>
>
>
> ------------------------------------------------------------------------
> Do you Yahoo!?
> With a free 1 GB, there's more in store with Yahoo! Mail.
>
>


-------------------------------------------------
If you wish to unsubscribe from this list, please
send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------



Do you Yahoo!?
With a free 1 GB, there's more in store with Yahoo! Mail.

Reply via email to