Hi,

I've got two element groups as shown in this example document, one using
element text items, one using attribute value items:

<document>
  <elementItemList>
    <item>abc</item>
    <item>def</item>
    <item>ghi</item>
  </elementItemList>
  <attributeItemList>
    <item code="abc"/>
    <item code="def"/>
    <item code="ghi"/>
  </attributeItemList>
</document>

Both <item/> groups are mapped to collections (items in the collections
are of type java.lang.String):

<binding>
  <mapping name="document" class="test.MyDocument">
    <structure name="elementItemList">
      <collection field="elementItemList" 
         factory="org.jibx.runtime.Utility.arrayListFactory">
        <structure name="item" value-style="element" usage="optional"/>
      </collection>
    </structure>
    <structure name="attributeItemList">
      <collection field="attributeItemList" 
          factory="org.jibx.runtime.Utility.arrayListFactory">
        <structure name="item" value-style="attribute" usage="optional">
          <value name="code" style="attribute"/>
        </structure>
      </collection>
    </structure>
  </mapping>
</binding> 

in this class:

package test;
import java.util.List;
public class MyDocument {
  // both are collections of java.util.String
  private List elementItemList;
  private List attributeItemList;

  // get/set methods are defined for both lists
  public List getElementItemList() {
    return elementItemList;
  }
  public void setElementItemList(List theList) {
    elementItemList = theList;
  }
  public List getAttributeItemList() {
    return attributeItemList;
  }
  public void setAttributeItemList(List theList) {
    attributeItemList = theList;
  }
}

Attempts to bind the MyDocument.class fail on the <value/> element
in the binding file:

 [bind] Running binding compiler version jibx-rc1
 [bind] Error: Need deserializer or constructor from string for type 
        java.lang.Object for value element at (line 12, col 49, in 
          JiBX/bin/CollectionAttributeItemTest-binding.xml)

So, the element item mapping works but the attribute item mapping does
not.  Is there a way to map attribute items, like the above, into a
collection, without resorting to the deserializer/constructor as
suggested by the error message?  

Perhaps I'm missing something, but, since the element item defaults to
mapping the element text to java.lang.String typed items (correct?),
couldn't a similar behaviour apply to attribute items? 

...Leif




-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
jibx-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to