java.io.NotSerializableException:为参数qualifiedCurrency定义的设置方法采用接口类型的参数

时间:2018-07-18 08:34:15

标签: java corda

尝试从Corda V1迁移到V3。在V1中运行正常,但是在使用Corda V3之后,其抛出的错误低于错误-

  

java.util.concurrent.ExecutionException:   java.io.NotSerializableException:   net.corda.core.contracts.TransactionState->   数据(net.corda.core.contracts.ContractState)->为   参数qualitedCurrency采用接口类型的参数   java.util.List但基础类型为java.util.List   -> com.xxx.agreementnegotiation.state.AgreementNegotiationState类

     

在java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:357)     atjava.util.concurrent.CompletableFuture.get(CompletableFuture.java:1895)     在   net.corda.core.internal.concurrent.CordaFutureImpl.get(CordaFutureImpl.kt)     在   com.xxx.agreementnegotiation.api.AgreementNegotiationApi.startInitFlow(AgreementNegotiationApi.java:95)     在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     在   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     在java.lang.reflect.Method.invoke(Method.java:498)在   org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory $ 1.invoke(ResourceMethodInvocationHandlerFactory.java:81)     在   org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher $ 1.run(AbstractJavaResourceMethodDispatcher.java:144)     在   org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:161)     在   org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider $ ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:160)     在   org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:99)     在   org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:389)     在   org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:347)     在   org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102)     在   org.glassfish.jersey.server.ServerRuntime $ 2.run(ServerRuntime.java:326)     在org.glassfish.jersey.internal.Errors $ 1.call(Errors.java:271)处   org.glassfish.jersey.internal.Errors $ 1.call(Errors.java:267)在   org.glassfish.jersey.internal.Errors.process(Errors.java:315)在   org.glassfish.jersey.internal.Errors.process(Errors.java:297)在   org.glassfish.jersey.internal.Errors.process(Errors.java:267)在   org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317)     在   org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:305)     在   org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1154)     在   org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:473)     在   org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:427)     在   org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:388)     在   org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:341)     在   org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:228)     在   org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:841)     在   org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:535)     在   org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:188)     在   org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1253)     在   org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:168)     在   org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:473)     在   org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:166)     在   org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1155)     在   org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)     在   org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:126)     在   org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)     在org.eclipse.jetty.server.Server.handle(Server.java:561)处   org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:334)在   org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:251)     在   org.eclipse.jetty.io.AbstractConnection $ ReadCallback.succeeded(AbstractConnection.java:279)     在org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:104)     在   org.eclipse.jetty.io.ChannelEndPoint $ 2.run(ChannelEndPoint.java:124)     在   org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:247)     在   org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.produce(EatWhatYouKill.java:140)     在   org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:131)     在   org.eclipse.jetty.util.thread.ReservedThreadExecutor $ ReservedThread.run(ReservedThreadExecutor.java:243)     在   org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:679)     在   org.eclipse.jetty.util.thread.QueuedThreadPool $ 2.run(QueuedThreadPool.java:597)

     

at java.lang.Thread.run(Thread.java:748)由以下原因引起:   java.io.NotSerializableException:   net.corda.core.contracts.TransactionState->   数据(net.corda.core.contracts.ContractState)->为   参数qualitedCurrency采用接口类型的参数   java.util.List但基础类型为java.util.List   -> com.xxx.agreementnegotiation.state.AgreementNegotiationState类

我的状态的一部分

public class AgreementNegotiationState extends AgreementStateTemplate implements QueryableState {
private String baseCurrency;
private List<String> eligibleCurrency;
private int deliveryAmount;

public String getBaseCurrency() {
    return baseCurrency;
}

public void setBaseCurrency(String baseCurrency) {
    this.baseCurrency = baseCurrency;
}

public List<String> getEligibleCurrency() {
    return eligibleCurrency;
}

public void setEligibleCurrency(List<String> eligibleCurrency) {
    this.eligibleCurrency = eligibleCurrency;
}

public int getDeliveryAmount() {
    return deliveryAmount;
}

public void setDeliveryAmount(int deliveryAmount) {
    this.deliveryAmount = deliveryAmount;
}

}

请协助。

2 个答案:

答案 0 :(得分:0)

这是Corda 3中的错误。它将在Corda 4中修复。

与此同时,解决方法是将eligibleCurrency更改为List<?>,并根据需要强制转换其元素:

private List<?> eligibleCurrency;

public List<?> getEligibleCurrency() {
    return eligibleCurrency;
}

public void setEligibleCurrency(List<?> eligibleCurrency) {
    this.eligibleCurrency = eligibleCurrency;
}

答案 1 :(得分:0)

根据corda V3,集合是不可变的,因此您不能添加到现有集合中。解决方案是创建一个函数,该函数获取现有集合的副本并将其添加到其中,最后将其引用到合格货币列表中。 / p>

private Collection<SupportingDocument> supportingDocs;
public void addSupportingDoc(SupportingDocument supportingDoc) {

    //since corda 3.1 has unmodifiable collection
    List<SupportingDocument> suppDoc = new ArrayList<SupportingDocument>();
    for(SupportingDocument existingDoc : supportingDocs){
        suppDoc.add(existingDoc);
    }
    // adding new document
    suppDoc.add(supportingDoc);
    this.supportingDocs = Collections.unmodifiableCollection(suppDoc);
}

我希望这是有道理的