castor
  1. castor
  2. CASTOR-477

Exception with same type collections and location= [TESTCASE]

    Details

    • Type: Bug Bug
    • Status: Open Open
    • Priority: Critical Critical
    • Resolution: Unresolved
    • Affects Version/s: 0.9.5
    • Fix Version/s: None
    • Component/s: XML
    • Labels:
      None
    • Environment:
      Operating System: All
      Platform: PC
    • Bugzilla Id:
      1337
    • Number of attachments :
      0

      Description

      I have attached a testcode which demonstrates the problem. The testcase model
      is as follows: A RuleBase has a collection of Rules, and each Rule has a
      collection of AllowHosts and DenyHosts (both of type Host).

      Castor marshalls the objects correctly but throws a SAXException when parsing
      the XML it generated. I think this is due to the fact that both collections are
      the same type, if you comment out the DenyHosts field definition then it works.

      I have tried to fix this but I'm not very familiar with the Castor code.

        Activity

        Hide
        dummy002 added a comment -

        Created an attachment (id=297)
        Test case

        Show
        dummy002 added a comment - Created an attachment (id=297) Test case
        Hide
        dummy002 added a comment -

        It seems Castors state is getting confused by identically named elements. If
        you replace the mappings for the AllowHosts and DenyHosts with these then it works:

        <field name="AllowHosts" type="Host" collection="collection">
        <bind-xml name="allow" location="allows"/>
        </field>

        <field name="DenyHosts" type="Host" collection="collection">
        <bind-xml name="deny" location="denys"/>
        </field>

        However this doesn't work:

        <field name="AllowHosts" type="Host" collection="collection">
        <bind-xml name="allow" location="allow"/>
        </field>

        <field name="DenyHosts" type="Host" collection="collection">
        <bind-xml name="deny" location="deny"/>
        </field>

        Show
        dummy002 added a comment - It seems Castors state is getting confused by identically named elements. If you replace the mappings for the AllowHosts and DenyHosts with these then it works: <field name="AllowHosts" type="Host" collection="collection"> <bind-xml name="allow" location="allows"/> </field> <field name="DenyHosts" type="Host" collection="collection"> <bind-xml name="deny" location="denys"/> </field> However this doesn't work: <field name="AllowHosts" type="Host" collection="collection"> <bind-xml name="allow" location="allow"/> </field> <field name="DenyHosts" type="Host" collection="collection"> <bind-xml name="deny" location="deny"/> </field>
        Hide
        Keith Visco added a comment -

        Hi Niall,

        I look into the issues. However a quick note. If you want your collections to be
        wrapped in an element name, you can also try the container="false" trick:

        <field name="AllowHosts" type="Host" collection="collection" container="false">
        <bind-xml name="allow/>
        </field>

        <field name="DenyHosts" type="Host" collection="collection" container="false">
        <bind-xml name="deny"/>
        </field>

        Show
        Keith Visco added a comment - Hi Niall, I look into the issues. However a quick note. If you want your collections to be wrapped in an element name, you can also try the container="false" trick: <field name="AllowHosts" type="Host" collection="collection" container="false"> <bind-xml name="allow/> </field> <field name="DenyHosts" type="Host" collection="collection" container="false"> <bind-xml name="deny"/> </field>
        Hide
        Denis Howlett added a comment -

        I've also just come up against this problem. I have some XML of the form:

        <KnowledgeBase>
        <obj id="obj1">
        <parents>
        <objLink id="obj0"/>
        </parents>
        <children>
        <objLink id="obj2"/>
        <objLink id="obj3"/>
        </children>
        </obj>
        ...
        </KnowledgeBase>

        So there are two elements that contain objLinks. I wanted to map these to
        appropriate fields using the location attribute. If I have one or the other it
        works, but if I have both, then I get:

        SAXException: unable to add 'ObjLink' to <KnowledgeBase> due to the following
        exception: java.lang.IllegalArgumentException: object is not an instance of
        declaring class.

        My field definitions are both of the form:

        <field name="parents"
        type="testing.castorTest.ObjLink"
        collection="arraylist">
        <bind-xml name="ObjLink" location="Parents"/>
        </field>

        I've tried putting container="false" but that gives a different error about not
        having a field called "ObjLink". I can send sample code if that's useful.

        Show
        Denis Howlett added a comment - I've also just come up against this problem. I have some XML of the form: <KnowledgeBase> <obj id="obj1"> <parents> <objLink id="obj0"/> </parents> <children> <objLink id="obj2"/> <objLink id="obj3"/> </children> </obj> ... </KnowledgeBase> So there are two elements that contain objLinks. I wanted to map these to appropriate fields using the location attribute. If I have one or the other it works, but if I have both, then I get: SAXException: unable to add 'ObjLink' to <KnowledgeBase> due to the following exception: java.lang.IllegalArgumentException: object is not an instance of declaring class. My field definitions are both of the form: <field name="parents" type="testing.castorTest.ObjLink" collection="arraylist"> <bind-xml name="ObjLink" location="Parents"/> </field> I've tried putting container="false" but that gives a different error about not having a field called "ObjLink". I can send sample code if that's useful.
        Hide
        Keith Visco added a comment -

        Denis, the bind-xml name and location are case-sensitive, you should change it
        to:

        <bind-xml name="objLink" location="parents"/>

        Show
        Keith Visco added a comment - Denis, the bind-xml name and location are case-sensitive, you should change it to: <bind-xml name="objLink" location="parents"/>

          People

          • Assignee:
            Unassigned
            Reporter:
            dummy002
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: