如何修复java.lang.ClassCastException?

时间:2016-08-23 11:32:40

标签: c# soap

以下是Propertyware API中使用的代码部分。

<?php
/**
 * Created by PhpStorm.
 * Date: 08/08/16
 * Time: 18:28
 */

namespace RestBundle\Controller;


use RestBundle\Form\StatusType;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use FOS\RestBundle\Controller\FOSRestController;
use Symfony\Component\HttpKernel\Exception\HttpException;

use RestBundle\Entity\Status;
class StatusController extends FOSRestController
{

    public function getStatusAction()
    {
        $em = $this->getDoctrine()->getManager();
        $user = $em->getRepository('RestBundle:Status')->findAll();

        return $user;
    }

    public function getStatuAction($id)
    {
        $em = $this->getDoctrine()->getManager();
        $user = $em->getRepository('RestBundle:Status')->find($id);

        if (!$id) {
            throw new HttpException(400, "Invalid id");
        }


        return $user;
    }

    public function postStatusAction(Request $request)
    {
        $user = new Status();
        $json = json_decode($request->getContent(), true);
        $user->setNome($json['nome']);
        $em = $this->getDoctrine()->getManager();
        $em->persist($user);
        $em->flush();
        return $user;
    }

}

在上面的代码中,我需要使用“appendOwnerLedgerItems”方法在Propertyware中创建所有者贡献条目。为此,我尝试使用以下逻辑,但它失败了。错误消息是“java.lang.ClassCastException:[Lcom.realpage.propertyware.web.service.soap.AbstractLedgerItemDTO;无法转换为[Lcom.realpage.propertyware.web.service.soap.AbstractOwnerLedgerItemDTO;”

public OwnerLedger appendOwnerLedgerItems(OwnerLedger ownerLedger, Owner owner) {
    object[] results = this.Invoke("appendOwnerLedgerItems", new object[] {
                ownerLedger,
                owner});
    return ((OwnerLedger)(results[0]));
}

public partial class OwnerLedger : Ledger {
}

public abstract partial class Ledger : ClientDataContainer {

private LedgerItem[] itemsField;

/// <remarks/>
[System.Xml.Serialization.SoapElementAttribute(IsNullable=true)]
public LedgerItem[] items {
    get {
        return this.itemsField;
    }
    set {
        this.itemsField = value;
    }
}
}

public abstract partial class LedgerItem : FinancialTransaction {
}

public abstract partial class OwnerLedgerItem : LedgerItem {
}

public partial class OwnerContribution : OwnerLedgerItem {

private string commentsField;

private System.Nullable<System.DateTime> dateField;

private string paymentTypeField;

private string referenceNumberField;

/// <remarks/>
[System.Xml.Serialization.SoapElementAttribute(IsNullable=true)]
public string comments {
    get {
        return this.commentsField;
    }
    set {
        this.commentsField = value;
    }
}

/// <remarks/>
[System.Xml.Serialization.SoapElementAttribute(IsNullable=true)]
public System.Nullable<System.DateTime> date {
    get {
        return this.dateField;
    }
    set {
        this.dateField = value;
    }
}

/// <remarks/>
[System.Xml.Serialization.SoapElementAttribute(IsNullable=true)]
public string paymentType {
    get {
        return this.paymentTypeField;
    }
    set {
        this.paymentTypeField = value;
    }
}

/// <remarks/>
[System.Xml.Serialization.SoapElementAttribute(IsNullable=true)]
public string referenceNumber {
    get {
        return this.referenceNumberField;
    }
    set {
        this.referenceNumberField = value;
    }
}
}

如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

我对Propertyware了解不多,但你可以试试这个,基本上改变传递给invoke方法的对象的顺序:

public OwnerLedger appendOwnerLedgerItems(OwnerLedger ownerLedger, Owner owner) {
    object[] results = this.Invoke("appendOwnerLedgerItems", new object[] {
                owner, ownerLedger});
    return ((OwnerLedger)(results[0]));
}