문제

I have this Java-Castor issue while mapping a hierarchy. Thanks for your time.

I have this XML file:

<RESULT>
  <RESULTCODE>OK</RESULTCODE>
  <ERRORS />
  <COMPANIES>
    <COMPANY VD="107795641" NAME="COMPANYA"
    RATING="" CIF="ABCD3435" ID="7671" NUM="0" />
    <COMPANY VD="102167561" NAME="COMPANYB"
    RATING="" CIF="ABCD1234" ID="6642" NUM="1" />
  </COMPANIES>
</RESULT>

This Java hierarchy:

public class RentedWSResult 
{
    private boolean success;

    private List<RentedWSResultError> errors;
}

public class GetCompaniesRentedWSResult extends RentedWSResult 
{
    private List<RentedCompany> rentedCompanies;
}

And these Castor Mappings:

<mapping>
    <class name="RentedWSResult">
    <map-to xml="RESULT" />
    <field name="success" type="string" handler="BooleanStringHandler">
        <bind-xml name="RESULTCODE" />
    </field>
    <field name="errors" type="RentedWSResultError" collection="arraylist"> 
        <bind-xml name="ERROR" location="ERRORS" />
    </field>
    </class>
</mapping>

<mapping>
    <include href="RentedWSResultMarshallConfig.xml"/>
    <class name="GetCompaniesRentedWSResult" >
    <field name="rentedCompanies" type="RentedCompany" collection="arraylist">
        <bind-xml name="COMPANY" location="COMPANIES" />
    </field>
    </class>
</mapping>

It's not working, getting this error:

Unable to find FieldDescriptor for 'COMPANIES' in ClassDescriptor of RESULT
도움이 되었습니까?

해결책

There is no relationship between your classes in the mapping file.

With the info you provided I put together a mapping that works. It assumes that your RentedWSResult is your container class for your other elements.

<mapping>
    <include href="GetCompaniesRentedWSResultBinding.xml"/>

    <class name="RentedWSResult">
        <map-to xml="RESULT" />
        <field name="success" type="string">
            <bind-xml name="RESULTCODE" />
        </field>

        <field name="rentedCompanies" type="GetCompaniesRentedWSResult"> 
            <bind-xml name="COMPANIES" />
        </field>
    </class>

 </mapping>

<mapping>
    <class name="GetCompaniesRentedWSResult" >
        <field name="rentedCompanies" type="RentedCompany" collection="arraylist">
            <bind-xml name="COMPANY" />
        </field>
    </class>

    <class name="RentedCompany" >
    <field name="vd" type="string">
            <bind-xml name="vd" node="attribute" />
        </field>

        <field name="name" type="string">
            <bind-xml name="name" node="attribute"/>
        </field>

        <field name="rating" type="string">
            <bind-xml name="rating" node="attribute"/>
        </field>

    </class>
</mapping>

다른 팁

Only solution I've found to this issue is to include all mappings in a single file as you have done. It's inconvenient but I think it's as good as it gets. I've read elsewhere online that this is an issue Castor can experience depending on which class loader is in play. It will look for the included mappings in the bin folder of the class loader which obviously isn't the correct place. (websphere in my case)

You might be able to put an absolute path i.e.

<include href="file:////C://mapping.xml" />

but I haven't been able to verify if this works and ultimately wouldn't be very portable or convenient solution as it is specific to the deployment environment.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top