在Corda V3.1中创建状态时出现java.io.NotSerializableException

时间:2018-04-12 19:56:46

标签: serialization deserialization corda

从Corda V2迁移到Corda V3.1时。无法保存或创建状态,在异常之下没有找到序列化的构造函数但合同状态有默认构造函数和parmatrised构造函数。

[WARN ] 2018-04-12T17:40:09,773Z [Node thread-1] flow.[f1e07b24-6f07-4e2b-a9cf-c9f92c14985a].run - Terminated by unexpected exception {}
java.io.NotSerializableException: net.corda.core.contracts.TransactionState -> data(net.corda.core.contracts.ContractState) -> No constructor for deserialization found for class com.demo.project.nodes.states.ContractState.
    at net.corda.nodeapi.internal.serialization.amqp.SerializationHelperKt.constructorForDeserialization(SerializationHelper.kt:50) ~[corda-node-api-3.1-corda.jar:?]
    at net.corda.nodeapi.internal.serialization.amqp.ObjectSerializer.<init>(ObjectSerializer.kt:19) ~[corda-node-api-3.1-corda.jar:?]
    at net.corda.nodeapi.internal.serialization.amqp.SerializerFactory$makeClassSerializer$1.apply(SerializerFactory.kt:271) ~[corda-node-api-3.1-corda.jar:?]
    at net.corda.nodeapi.internal.serialization.amqp.SerializerFactory$makeClassSerializer$1.apply(SerializerFactory.kt:40) ~[corda-node-api-3.1-corda.jar:?]
    at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(Unknown Source) ~[?:1.8.0_161]
    at net.corda.nodeapi.internal.serialization.amqp.SerializerFactory.makeClassSerializer(SerializerFactory.kt:255) ~[corda-node-api-3.1-corda.jar:?]
    at net.corda.nodeapi.internal.serialization.amqp.SerializerFactory.get(SerializerFactory.kt:100) ~[corda-node-api-3.1-corda.jar:?]
    at net.corda.nodeapi.internal.serialization.amqp.SerializationOutput.writeObject$node_api(SerializationOutput.kt:98) ~[corda-node-api-3.1-corda.jar:?]
    at net.corda.nodeapi.internal.serialization.amqp.SerializationOutput.writeObjectOrNull$node_api(SerializationOutput.kt:93) ~[corda-node-api-3.1-corda.jar:?]
    at net.corda.nodeapi.internal.serialization.amqp.PropertySerializer$DescribedTypePropertySerializer.writeProperty(PropertySerializer.kt:84) ~[corda-node-api-3.1-corda.jar:?]
    at net.corda.nodeapi.internal.serialization.amqp.ObjectSerializer$writeObject$$inlined$ifThrowsAppend$lambda$1$1.invoke(ObjectSerializer.kt:66) ~[corda-node-api-3.1-corda.jar:?]
    at net.corda.nodeapi.internal.serialization.amqp.ObjectSerializer$writeObject$$inlined$ifThrowsAppend$lambda$1$1.invoke(ObjectSerializer.kt:17) ~[corda-node-api-3.1-corda.jar:?]
    at net.corda.nodeapi.internal.serialization.amqp.SerializationHelperKt.withList(SerializationHelper.kt:401) ~[corda-node-api-3.1-corda.jar:?]
    at net.corda.nodeapi.internal.serialization.amqp.ObjectSerializer$writeObject$$inlined$ifThrowsAppend$lambda$1.invoke(ObjectSerializer.kt:64) ~[corda-node-api-3.1-corda.jar:?]
    at net.corda.nodeapi.internal.serialization.amqp.ObjectSerializer$writeObject$$inlined$ifThrowsAppend$lambda$1.invoke(ObjectSerializer.kt:17) ~[corda-node-api-3.1-corda.jar:?]
    at net.corda.nodeapi.internal.serialization.amqp.SerializationHelperKt.withDescribed(SerializationHelper.kt:390) ~[corda-node-api-3.1-corda.jar:?]
    at net.corda.nodeapi.internal.serialization.amqp.ObjectSerializer.writeObject(ObjectSerializer.kt:62) ~[corda-node-api-3.1-corda.jar:?]
    at net.corda.nodeapi.internal.serialization.amqp.SerializationOutput.writeObject$node_api(SerializationOutput.kt:106) ~[corda-node-api-3.1-corda.jar:?]
    at net.corda.nodeapi.internal.serialization.amqp.SerializationOutput.writeObject$node_api$default(SerializationOutput.kt:97) ~[corda-node-api-3.1-corda.jar:?]
    at net.corda.nodeapi.internal.serialization.amqp.SerializationOutput.writeObject$node_api(SerializationOutput.kt:78) ~[corda-node-api-3.1-corda.jar:?]
    at net.corda.nodeapi.internal.serialization.amqp.SerializationOutput$_serialize$1$1.invoke(SerializationOutput.kt:64) ~[corda-node-api-3.1-corda.jar:?]
    at net.corda.nodeapi.internal.serialization.amqp.SerializationOutput$_serialize$1$1.invoke(SerializationOutput.kt:22) ~[corda-node-api-3.1-corda.jar:?]
    at net.corda.nodeapi.internal.serialization.amqp.SerializationHelperKt.withList(SerializationHelper.kt:401) ~[corda-node-api-3.1-corda.jar:?]
    at net.corda.nodeapi.internal.serialization.amqp.SerializationOutput$_serialize$1.invoke(SerializationOutput.kt:63) ~[corda-node-api-3.1-corda.jar:?]
    at net.corda.nodeapi.internal.serialization.amqp.SerializationOutput$_serialize$1.invoke(SerializationOutput.kt:22) ~[corda-node-api-3.1-corda.jar:?]
    at net.corda.nodeapi.internal.serialization.amqp.SerializationHelperKt.withDescribed(SerializationHelper.kt:390) ~[corda-node-api-3.1-corda.jar:?]
    at net.corda.nodeapi.internal.serialization.amqp.SerializationOutput._serialize$node_api(SerializationOutput.kt:62) ~[corda-node-api-3.1-corda.jar:?]
    at net.corda.nodeapi.internal.serialization.amqp.SerializationOutput.serialize(SerializationOutput.kt:36) ~[corda-node-api-3.1-corda.jar:?]
    at net.corda.nodeapi.internal.serialization.amqp.AbstractAMQPSerializationScheme.serialize(AMQPSerializationScheme.kt:128) ~[corda-node-api-3.1-corda.jar:?]
    at net.corda.nodeapi.internal.serialization.SerializationFactoryImpl$serialize$1$1.invoke(SerializationScheme.kt:126) ~[corda-node-api-3.1-corda.jar:?]
    at net.corda.nodeapi.internal.serialization.SerializationFactoryImpl$serialize$1$1.invoke(SerializationScheme.kt:86) ~[corda-node-api-3.1-corda.jar:?]
    at net.corda.core.serialization.SerializationFactory.withCurrentContext(SerializationAPI.kt:66) ~[corda-core-3.1-corda.jar:?]
    at net.corda.nodeapi.internal.serialization.SerializationFactoryImpl$serialize$1.invoke(SerializationScheme.kt:126) ~[corda-node-api-3.1-corda.jar:?]
    at net.corda.nodeapi.internal.serialization.SerializationFactoryImpl$serialize$1.invoke(SerializationScheme.kt:86) ~[corda-node-api-3.1-corda.jar:?]
    at net.corda.core.serialization.SerializationFactory.asCurrent(SerializationAPI.kt:80) ~[corda-core-3.1-corda.jar:?]
    at net.corda.nodeapi.internal.serialization.SerializationFactoryImpl.serialize(SerializationScheme.kt:126) ~[corda-node-api-3.1-corda.jar:?]
    at net.corda.core.serialization.SerializationAPIKt.serialize(SerializationAPI.kt:221) ~[corda-core-3.1-corda.jar:?]
    at net.corda.core.serialization.SerializationAPIKt.serialize$default(SerializationAPI.kt:220) ~[corda-core-3.1-corda.jar:?]
    at net.corda.core.transactions.WireTransaction$Companion.createComponentGroups(WireTransaction.kt:242) ~[corda-core-3.1-corda.jar:?]
    at net.corda.core.transactions.TransactionBuilder$toWireTransactionWithContext$1.invoke(TransactionBuilder.kt:114) ~[corda-core-3.1-corda.jar:?]
    at net.corda.core.transactions.TransactionBuilder$toWireTransactionWithContext$1.invoke(TransactionBuilder.kt:36) ~[corda-core-3.1-corda.jar:?]
    at net.corda.core.serialization.SerializationFactory.withCurrentContext(SerializationAPI.kt:66) ~[corda-core-3.1-corda.jar:?]
    at net.corda.core.transactions.TransactionBuilder.toWireTransactionWithContext$core(TransactionBuilder.kt:113) ~[corda-core-3.1-corda.jar:?]
    at net.corda.core.transactions.TransactionBuilder.toWireTransactionWithContext$core$default(TransactionBuilder.kt:97) ~[corda-core-3.1-corda.jar:?]
    at net.corda.core.transactions.TransactionBuilder.toWireTransaction(TransactionBuilder.kt:95) ~[corda-core-3.1-corda.jar:?]
    at net.corda.core.transactions.TransactionBuilder.toLedgerTransaction(TransactionBuilder.kt:135) ~[corda-core-3.1-corda.jar:?]
    at net.corda.core.transactions.TransactionBuilder.verify(TransactionBuilder.kt:143) ~[corda-core-3.1-corda.jar:?]
    at com.demo.project.nodes.initiators.ContractStateFlowInitiator.call(ContractStateFlowInitiator.java:54) ~[project-node-1.0.jar:?]
    at com.demo.project.nodes.initiators.ContractStateFlowInitiator.call(ContractStateFlowInitiator.java:25) ~[project-node-1.0.jar:?]
    at net.corda.node.services.statemachine.FlowStateMachineImpl.run(FlowStateMachineImpl.kt:96) [corda-node-3.1-corda.jar:?]
    at net.corda.node.services.statemachine.FlowStateMachineImpl.run(FlowStateMachineImpl.kt:44) [corda-node-3.1-corda.jar:?]
    at co.paralleluniverse.fibers.Fiber.run1(Fiber.java:1092) [quasar-core-0.7.9-jdk8.jar:0.7.9]
    at co.paralleluniverse.fibers.Fiber.exec(Fiber.java:788) [quasar-core-0.7.9-jdk8.jar:0.7.9]
    at co.paralleluniverse.fibers.RunnableFiberTask.doExec(RunnableFiberTask.java:100) [quasar-core-0.7.9-jdk8.jar:0.7.9]
    at co.paralleluniverse.fibers.RunnableFiberTask.run(RunnableFiberTask.java:91) [quasar-core-0.7.9-jdk8.jar:0.7.9]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_161]
    at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_161]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(Unknown Source) [?:1.8.0_161]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source) [?:1.8.0_161]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [?:1.8.0_161]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [?:1.8.0_161]
    at net.corda.node.utilities.AffinityExecutor$ServiceAffinityExecutor$1$thread$1.run(AffinityExecutor.kt:62) [corda-node-3.1-corda.jar:?] 
Corda version :corda_release_version = '3.1-corda'
Corda Gradle Plugin Version: corda_gradle_plugins_version = '3.1.0'
Quasar Version: quasar_version = '0.7.9'
Boot Version :spring_boot_version = '1.5.9.RELEASE'

在ContractStateFlowInitiator类中验证合同时发生错误:txBuilder.verify(getServiceHub());

适用于2.0版的东西

即使使用corda 3.0版,错误仍然存​​在。我尝试将我的状态com.demo.project.nodes.states.ContractState重命名为com.demo.project.nodes.states.DemoContractState也在状态中创建了一个默认构造函数,但没有运气。

3 个答案:

答案 0 :(得分:2)

使用 @ConstructorForDeserialization

为您的参数化构造函数添加注释

虽然java doc提到使用注释[@CordaConstructor] - java doc需要在SerializationHelper.Kt中更新

在某些情况下,公证人也应该看到共享项目。

还要确保将-parmeters添加到所有子项目中 例如:

add_action('save_post_shop_order', 'update_wp_user_data', 50, 3 );
function update_wp_user_data( $post_id, $post, $update ) {

    // Checking that is not an autosave
    if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ){
            update_post_meta( $post_id, '_invoices_files', 'auto-save-verif' );
            return $post_id;
        }

    // Check the user’s permissions (for 'shop_manager' and 'administrator' user roles)
    if ( ! current_user_can( 'edit_shop_order', $post_id ) ){
            update_post_meta( $post_id, '_invoices_files', 'user-roles-verif' );
            return $post_id;
        }

    // Get the customer ID and check if it's valid
    $customer_id = get_post_meta( $post_id, '_customer_user', true );
    if( empty($customer_id) || $customer_id == 0 )
        return $post_id;

    // Set all field keys in arrays
    $field_keys = array('first_name', 'last_name', 'company', 'address_1', 'address_2', 'city',
        'postcode', 'country', 'state');
    $fields_keys2 = array('email', 'phone');

    foreach( $field_keys as $key ){
        if( isset($_POST['_billing_'.$key]) ){
            update_user_meta( $customer_id, 'billing_'.$key, sanitize_text_field( $_POST['_billing_'.$key] ) );
        }
        if( isset($_POST['_shipping_'.$key]) ){
            update_user_meta( $customer_id, 'shipping_'.$key, sanitize_text_field( $_POST['_shipping_'.$key] ) );
        }
    }

    foreach( $fields_keys2 as $key ){
        if( isset($_POST['_billing_'.$key]) ){
            update_user_meta( $customer_id, 'billing_'.$key, sanitize_text_field( $_POST['_billing_'.$key] ) );
        }
    }
}

答案 1 :(得分:0)

我也没有使用正在使用V2的V3源码。 并发生了相同的异常。 我认为StackTrace的内容有些不同,但我认为它会有所帮助。

Corda V3 Error java.util.concurrent.ExecutionException

答案 2 :(得分:0)

除了上述解决方案之外,在类的构造函数上添加@ConstructorForDeserialization,我们还需要在IDE设置中进行一些更改。

修复:在IntelliJ中:

Open the settings:
Windows: File -> Settings
osX: IntelliJ IDEA -> Preferences...
Go to Build, Execution, Deployment -> Compiler -> Java Compiler
Write -parameters in the Additional command line parameters field
Completely rebuild the project (Build -> Rebuild Project)

此corda训练营链接为参考:https://github.com/corda/bootcamp-cordapp/wiki/Troubleshooting

enter image description here