From 67623f04a30ec17c97fe34204a587492e66a3106 Mon Sep 17 00:00:00 2001 From: Chris Rankin Date: Mon, 2 Sep 2019 16:12:49 +0100 Subject: [PATCH 01/18] CORDA-3174: Implement Corda serialization modules. (#59) * Create DJVM serialization modules. * Create test cases for Array, List and List>. * Refactor SandboxPrimiveSerializer for all primitive types. * Implement SandboxCollectionSerializer to support Collection types. * Implement SandboxMapSerializer to support Map types. * Attempt to fix infinite loop when computing Collection and Map fingerprints. * Apply special handling when deserialising sandbox.java.lang.Character. * Remap Java primitive types to sandbox Java object types to deter evolution. * Use Class.getPackage().getName() to determine sandbox package name. * Implement SandboxEnumSerializer to support Enum types. * Implement SandboxPublicKeySerializer to support Java security keys. * Add serialization projects to the composite example project. * Implement serializers for BigInteger, BigDecimal, Currency and StringBuffer. * Test that deserialising does not instantiate the untrusted user classes. * Implement serializers for java.time.* types. * Add serialiser for BitSet - currently disabled until BitSet itself is supported. * Add serialisers for EnumSet and Class. * Include support for EnumMap in the SandboxMapSerializer. * Ensure the DJVM Example project's tests preserve @CordaSerializable. * Add support for UUID as a primitive type. * Use common abortReadOnly() method for declaring serialization as unsupported. * Streamline the API for deserialising into the sandbox. * Add preliminary support for deserialising X.509 certificates. * Implement serializer for java.util.Optional. * Refactor configuration of the sandbox serialization scheme. * Add tests for deserialising arrays of basic types. * Include method annotations in annotation stitching. This ensures that `@ConstructorForDeserialization` is not dropped. * Enable test for SandboxBitSetSerializer. * Enable tests for X.509 serializers. * Implement serializers for ProtonJ primitive types. * Serialize java.util.Date as a primitive type. * Add the bintray Gradle plugin to the serialisation modules. * Do not publish serialisation modules - they will become part of Corda itself. --- build.gradle | 102 ++++++ deserializers/build.gradle | 29 ++ .../deserializers/BitSetDeserializer.kt | 11 + .../deserializers/CertPathDeserializer.kt | 13 + .../deserializers/ClassDeserializer.kt | 11 + .../deserializers/CreateCollection.kt | 47 +++ .../deserializers/CreateCurrency.kt | 10 + .../deserializers/CreateFromString.kt | 10 + .../serialization/deserializers/CreateMap.kt | 48 +++ .../deserializers/Decimal128Deserializer.kt | 10 + .../deserializers/Decimal32Deserializer.kt | 10 + .../deserializers/Decimal64Deserializer.kt | 10 + .../deserializers/DescribeEnum.kt | 9 + .../deserializers/DurationDeserializer.kt | 11 + .../deserializers/EnumSetDeserializer.kt | 16 + .../deserializers/InstantDeserializer.kt | 11 + .../deserializers/JustForCasting.kt | 6 + .../deserializers/LocalDateDeserializer.kt | 11 + .../LocalDateTimeDeserializer.kt | 11 + .../deserializers/LocalTimeDeserializer.kt | 11 + .../deserializers/MonthDayDeserializer.kt | 11 + .../OffsetDateTimeDeserializer.kt | 11 + .../deserializers/OffsetTimeDeserializer.kt | 11 + .../deserializers/OptionalDeserializer.kt | 11 + .../deserializers/PeriodDeserializer.kt | 11 + .../deserializers/PublicKeyDecoder.kt | 11 + .../deserializers/SymbolDeserializer.kt | 10 + .../deserializers/UnsignedByteDeserializer.kt | 10 + .../UnsignedIntegerDeserializer.kt | 10 + .../deserializers/UnsignedLongDeserializer.kt | 10 + .../UnsignedShortDeserializer.kt | 10 + .../deserializers/X509CRLDeserializer.kt | 12 + .../X509CertificateDeserializer.kt | 12 + .../deserializers/YearDeserializer.kt | 11 + .../deserializers/YearMonthDeserializer.kt | 11 + .../deserializers/ZoneIdDeserializer.kt | 11 + .../ZonedDateTimeDeserializer.kt | 10 + .../serialization/AMQPSerializationScheme.kt | 89 +++++ .../serialization/DelegatingClassLoader.kt | 10 + .../SandboxSerializerFactoryFactory.kt | 85 +++++ .../djvm/serialization/SandboxWhitelist.kt | 13 + .../corda/djvm/serialization/Serialization.kt | 87 +++++ .../serializers/ExceptionUtils.kt | 38 +++ .../serializers/PrimitiveSerializer.kt | 28 ++ .../serializers/SandboxBitSetSerializer.kt | 31 ++ .../serializers/SandboxCertPathSerializer.kt | 31 ++ .../serializers/SandboxCharacterSerializer.kt | 33 ++ .../serializers/SandboxClassSerializer.kt | 54 +++ .../SandboxCollectionSerializer.kt | 120 +++++++ .../serializers/SandboxCurrencySerializer.kt | 39 +++ .../SandboxDecimal128Serializer.kt | 37 ++ .../serializers/SandboxDecimal32Serializer.kt | 36 ++ .../serializers/SandboxDecimal64Serializer.kt | 36 ++ .../serializers/SandboxDurationSerializer.kt | 31 ++ .../serializers/SandboxEnumSerializer.kt | 95 ++++++ .../serializers/SandboxEnumSetSerializer.kt | 35 ++ .../serializers/SandboxInstantSerializer.kt | 31 ++ .../serializers/SandboxLocalDateSerializer.kt | 31 ++ .../SandboxLocalDateTimeSerializer.kt | 31 ++ .../serializers/SandboxLocalTimeSerializer.kt | 31 ++ .../serializers/SandboxMapSerializer.kt | 114 +++++++ .../serializers/SandboxMonthDaySerializer.kt | 31 ++ .../SandboxOffsetDateTimeSerializer.kt | 31 ++ .../SandboxOffsetTimeSerializer.kt | 31 ++ .../serializers/SandboxOptionalSerializer.kt | 31 ++ .../serializers/SandboxPeriodSerializer.kt | 31 ++ .../serializers/SandboxPrimitiveSerializer.kt | 26 ++ .../serializers/SandboxPublicKeySerializer.kt | 40 +++ .../serializers/SandboxSymbolSerializer.kt | 38 +++ .../serializers/SandboxToStringSerializer.kt | 44 +++ .../SandboxUnsignedByteSerializer.kt | 36 ++ .../SandboxUnsignedIntegerSerializer.kt | 36 ++ .../SandboxUnsignedLongSerializer.kt | 37 ++ .../SandboxUnsignedShortSerializer.kt | 36 ++ .../serializers/SandboxX509CRLSerializer.kt | 40 +++ .../SandboxX509CertificateSerializer.kt | 40 +++ .../serializers/SandboxYearMonthSerializer.kt | 31 ++ .../serializers/SandboxYearSerializer.kt | 31 ++ .../serializers/SandboxZoneIdSerializer.kt | 33 ++ .../SandboxZonedDateTimeSerializer.kt | 48 +++ src/test/java/greymalkin/ExternalData.java | 13 + src/test/java/greymalkin/ExternalEnum.java | 11 + .../djvm/serialization/InnocentData.java | 22 ++ .../serialization/MultiConstructorData.java | 53 +++ .../djvm/serialization/VeryEvilData.java | 15 + .../DeserializeBigDecimalTest.kt | 51 +++ .../DeserializeBigIntegerTest.kt | 51 +++ .../serialization/DeserializeBitSetTest.kt | 41 +++ .../DeserializeCertificatesTest.kt | 135 ++++++++ .../serialization/DeserializeClassTest.kt | 60 ++++ .../DeserializeCollectionsTest.kt | 227 +++++++++++++ .../serialization/DeserializeCurrencyTest.kt | 47 +++ .../serialization/DeserializeEnumSetTest.kt | 45 +++ .../djvm/serialization/DeserializeEnumTest.kt | 57 ++++ .../serialization/DeserializeGenericsTest.kt | 81 +++++ .../serialization/DeserializeInstantTest.kt | 41 +++ ...rializeJavaWithMultipleConstructorsTest.kt | 41 +++ .../serialization/DeserializeLocalDateTest.kt | 41 +++ .../DeserializeLocalDateTimeTest.kt | 41 +++ .../serialization/DeserializeLocalTimeTest.kt | 41 +++ .../djvm/serialization/DeserializeMapsTest.kt | 211 ++++++++++++ .../serialization/DeserializeMonthDayTest.kt | 41 +++ .../DeserializeObjectArraysTest.kt | 318 ++++++++++++++++++ .../DeserializeOffsetDateTimeTest.kt | 41 +++ .../DeserializeOffsetTimeTest.kt | 41 +++ .../serialization/DeserializeOptionalTest.kt | 62 ++++ .../serialization/DeserializePeriodTest.kt | 41 +++ .../DeserializePrimitiveArraysTest.kt | 255 ++++++++++++++ .../DeserializePrimitivesTest.kt | 75 +++++ .../serialization/DeserializeProtonJTest.kt | 254 ++++++++++++++ .../serialization/DeserializePublicKeyTest.kt | 96 ++++++ .../DeserializeStringBufferTest.kt | 40 +++ .../serialization/DeserializeStringTest.kt | 75 +++++ .../serialization/DeserializeYearMonthTest.kt | 41 +++ .../djvm/serialization/DeserializeYearTest.kt | 41 +++ .../serialization/DeserializeZoneIdTest.kt | 53 +++ .../DeserializeZonedDateTimeTest.kt | 41 +++ .../djvm/serialization/LocalSerialization.kt | 60 ++++ .../serialization/SafeDeserialisationTest.kt | 89 +++++ .../corda/djvm/serialization/SandboxType.kt | 6 + .../net/corda/djvm/serialization/TestBase.kt | 139 ++++++++ src/test/resources/log4j2-test.xml | 17 + src/test/resources/testing.cert | Bin 0 -> 801 bytes src/test/scripts/generate-certificate.sh | 11 + 124 files changed, 5579 insertions(+) create mode 100644 build.gradle create mode 100644 deserializers/build.gradle create mode 100644 deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/BitSetDeserializer.kt create mode 100644 deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/CertPathDeserializer.kt create mode 100644 deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/ClassDeserializer.kt create mode 100644 deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/CreateCollection.kt create mode 100644 deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/CreateCurrency.kt create mode 100644 deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/CreateFromString.kt create mode 100644 deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/CreateMap.kt create mode 100644 deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/Decimal128Deserializer.kt create mode 100644 deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/Decimal32Deserializer.kt create mode 100644 deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/Decimal64Deserializer.kt create mode 100644 deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/DescribeEnum.kt create mode 100644 deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/DurationDeserializer.kt create mode 100644 deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/EnumSetDeserializer.kt create mode 100644 deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/InstantDeserializer.kt create mode 100644 deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/JustForCasting.kt create mode 100644 deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/LocalDateDeserializer.kt create mode 100644 deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/LocalDateTimeDeserializer.kt create mode 100644 deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/LocalTimeDeserializer.kt create mode 100644 deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/MonthDayDeserializer.kt create mode 100644 deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/OffsetDateTimeDeserializer.kt create mode 100644 deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/OffsetTimeDeserializer.kt create mode 100644 deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/OptionalDeserializer.kt create mode 100644 deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/PeriodDeserializer.kt create mode 100644 deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/PublicKeyDecoder.kt create mode 100644 deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/SymbolDeserializer.kt create mode 100644 deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/UnsignedByteDeserializer.kt create mode 100644 deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/UnsignedIntegerDeserializer.kt create mode 100644 deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/UnsignedLongDeserializer.kt create mode 100644 deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/UnsignedShortDeserializer.kt create mode 100644 deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/X509CRLDeserializer.kt create mode 100644 deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/X509CertificateDeserializer.kt create mode 100644 deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/YearDeserializer.kt create mode 100644 deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/YearMonthDeserializer.kt create mode 100644 deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/ZoneIdDeserializer.kt create mode 100644 deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/ZonedDateTimeDeserializer.kt create mode 100644 src/main/kotlin/net/corda/djvm/serialization/AMQPSerializationScheme.kt create mode 100644 src/main/kotlin/net/corda/djvm/serialization/DelegatingClassLoader.kt create mode 100644 src/main/kotlin/net/corda/djvm/serialization/SandboxSerializerFactoryFactory.kt create mode 100644 src/main/kotlin/net/corda/djvm/serialization/SandboxWhitelist.kt create mode 100644 src/main/kotlin/net/corda/djvm/serialization/Serialization.kt create mode 100644 src/main/kotlin/net/corda/djvm/serialization/serializers/ExceptionUtils.kt create mode 100644 src/main/kotlin/net/corda/djvm/serialization/serializers/PrimitiveSerializer.kt create mode 100644 src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxBitSetSerializer.kt create mode 100644 src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCertPathSerializer.kt create mode 100644 src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCharacterSerializer.kt create mode 100644 src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxClassSerializer.kt create mode 100644 src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCollectionSerializer.kt create mode 100644 src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCurrencySerializer.kt create mode 100644 src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDecimal128Serializer.kt create mode 100644 src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDecimal32Serializer.kt create mode 100644 src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDecimal64Serializer.kt create mode 100644 src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDurationSerializer.kt create mode 100644 src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxEnumSerializer.kt create mode 100644 src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxEnumSetSerializer.kt create mode 100644 src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxInstantSerializer.kt create mode 100644 src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxLocalDateSerializer.kt create mode 100644 src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxLocalDateTimeSerializer.kt create mode 100644 src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxLocalTimeSerializer.kt create mode 100644 src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxMapSerializer.kt create mode 100644 src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxMonthDaySerializer.kt create mode 100644 src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOffsetDateTimeSerializer.kt create mode 100644 src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOffsetTimeSerializer.kt create mode 100644 src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOptionalSerializer.kt create mode 100644 src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxPeriodSerializer.kt create mode 100644 src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxPrimitiveSerializer.kt create mode 100644 src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxPublicKeySerializer.kt create mode 100644 src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxSymbolSerializer.kt create mode 100644 src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxToStringSerializer.kt create mode 100644 src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedByteSerializer.kt create mode 100644 src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedIntegerSerializer.kt create mode 100644 src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedLongSerializer.kt create mode 100644 src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedShortSerializer.kt create mode 100644 src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxX509CRLSerializer.kt create mode 100644 src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxX509CertificateSerializer.kt create mode 100644 src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxYearMonthSerializer.kt create mode 100644 src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxYearSerializer.kt create mode 100644 src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxZoneIdSerializer.kt create mode 100644 src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxZonedDateTimeSerializer.kt create mode 100644 src/test/java/greymalkin/ExternalData.java create mode 100644 src/test/java/greymalkin/ExternalEnum.java create mode 100644 src/test/java/net/corda/djvm/serialization/InnocentData.java create mode 100644 src/test/java/net/corda/djvm/serialization/MultiConstructorData.java create mode 100644 src/test/java/net/corda/djvm/serialization/VeryEvilData.java create mode 100644 src/test/kotlin/net/corda/djvm/serialization/DeserializeBigDecimalTest.kt create mode 100644 src/test/kotlin/net/corda/djvm/serialization/DeserializeBigIntegerTest.kt create mode 100644 src/test/kotlin/net/corda/djvm/serialization/DeserializeBitSetTest.kt create mode 100644 src/test/kotlin/net/corda/djvm/serialization/DeserializeCertificatesTest.kt create mode 100644 src/test/kotlin/net/corda/djvm/serialization/DeserializeClassTest.kt create mode 100644 src/test/kotlin/net/corda/djvm/serialization/DeserializeCollectionsTest.kt create mode 100644 src/test/kotlin/net/corda/djvm/serialization/DeserializeCurrencyTest.kt create mode 100644 src/test/kotlin/net/corda/djvm/serialization/DeserializeEnumSetTest.kt create mode 100644 src/test/kotlin/net/corda/djvm/serialization/DeserializeEnumTest.kt create mode 100644 src/test/kotlin/net/corda/djvm/serialization/DeserializeGenericsTest.kt create mode 100644 src/test/kotlin/net/corda/djvm/serialization/DeserializeInstantTest.kt create mode 100644 src/test/kotlin/net/corda/djvm/serialization/DeserializeJavaWithMultipleConstructorsTest.kt create mode 100644 src/test/kotlin/net/corda/djvm/serialization/DeserializeLocalDateTest.kt create mode 100644 src/test/kotlin/net/corda/djvm/serialization/DeserializeLocalDateTimeTest.kt create mode 100644 src/test/kotlin/net/corda/djvm/serialization/DeserializeLocalTimeTest.kt create mode 100644 src/test/kotlin/net/corda/djvm/serialization/DeserializeMapsTest.kt create mode 100644 src/test/kotlin/net/corda/djvm/serialization/DeserializeMonthDayTest.kt create mode 100644 src/test/kotlin/net/corda/djvm/serialization/DeserializeObjectArraysTest.kt create mode 100644 src/test/kotlin/net/corda/djvm/serialization/DeserializeOffsetDateTimeTest.kt create mode 100644 src/test/kotlin/net/corda/djvm/serialization/DeserializeOffsetTimeTest.kt create mode 100644 src/test/kotlin/net/corda/djvm/serialization/DeserializeOptionalTest.kt create mode 100644 src/test/kotlin/net/corda/djvm/serialization/DeserializePeriodTest.kt create mode 100644 src/test/kotlin/net/corda/djvm/serialization/DeserializePrimitiveArraysTest.kt create mode 100644 src/test/kotlin/net/corda/djvm/serialization/DeserializePrimitivesTest.kt create mode 100644 src/test/kotlin/net/corda/djvm/serialization/DeserializeProtonJTest.kt create mode 100644 src/test/kotlin/net/corda/djvm/serialization/DeserializePublicKeyTest.kt create mode 100644 src/test/kotlin/net/corda/djvm/serialization/DeserializeStringBufferTest.kt create mode 100644 src/test/kotlin/net/corda/djvm/serialization/DeserializeStringTest.kt create mode 100644 src/test/kotlin/net/corda/djvm/serialization/DeserializeYearMonthTest.kt create mode 100644 src/test/kotlin/net/corda/djvm/serialization/DeserializeYearTest.kt create mode 100644 src/test/kotlin/net/corda/djvm/serialization/DeserializeZoneIdTest.kt create mode 100644 src/test/kotlin/net/corda/djvm/serialization/DeserializeZonedDateTimeTest.kt create mode 100644 src/test/kotlin/net/corda/djvm/serialization/LocalSerialization.kt create mode 100644 src/test/kotlin/net/corda/djvm/serialization/SafeDeserialisationTest.kt create mode 100644 src/test/kotlin/net/corda/djvm/serialization/SandboxType.kt create mode 100644 src/test/kotlin/net/corda/djvm/serialization/TestBase.kt create mode 100644 src/test/resources/log4j2-test.xml create mode 100644 src/test/resources/testing.cert create mode 100755 src/test/scripts/generate-certificate.sh diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000000..30395c53f3 --- /dev/null +++ b/build.gradle @@ -0,0 +1,102 @@ +plugins { + id 'org.jetbrains.kotlin.jvm' + id 'java-library' + id 'idea' +} + +ext { + corda_version = '5.0-SNAPSHOT' +} + +description 'Serialization support for the DJVM' + +configurations { + sandboxTesting + jdkRt.resolutionStrategy { + // Always check the repository for a newer SNAPSHOT. + cacheChangingModulesFor 0, 'seconds' + } +} + +allprojects { + repositories { + maven { + url "$artifactory_contextUrl/corda-dev" + } + } + + configurations{ + // This is for the latest deterministic Corda SNAPSHOT artifacts... + [ compileClasspath, runtimeClasspath ].forEach { cfg -> + cfg.resolutionStrategy { + // Always check the repository for a newer SNAPSHOT. + cacheChangingModulesFor 0, 'seconds' + + dependencySubstitution { + substitute module("net.corda:corda-core:$corda_version") with module("net.corda:corda-core-deterministic:$corda_version") + substitute module("net.corda:corda-serialization:$corda_version") with module("net.corda:corda-serialization-deterministic:$corda_version") + } + } + } + } + + /* + * Corda serialization requires parameter names + * to be available via Java reflection. + */ + tasks.withType(JavaCompile) { + options.compilerArgs += '-parameters' + } + + tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile) { + kotlinOptions { + javaParameters = true + } + } +} + +dependencies { + api project(path: ':djvm', configuration: 'shadow') + api "net.corda:corda-core:$corda_version" + api "net.corda:corda-serialization:$corda_version" + implementation project(':serialization:deserializers') + + testImplementation "org.junit.jupiter:junit-jupiter-api:$junit_jupiter_version" + testImplementation "org.junit.jupiter:junit-jupiter-params:$junit_jupiter_version" + testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junit_jupiter_version" + + // Test utilities + testImplementation "org.assertj:assertj-core:$assertj_version" + testRuntimeOnly "org.apache.logging.log4j:log4j-slf4j-impl:$log4j_version" + jdkRt "net.corda:deterministic-rt:latest.integration" + + // The DJVM will need this classpath to run the unit tests. + sandboxTesting files(sourceSets.getByName("test").output) + sandboxTesting(project(':serialization:deserializers')) { + exclude group: 'net.corda' + } + sandboxTesting "net.corda:corda-serialization-deterministic:$corda_version" + sandboxTesting "org.slf4j:slf4j-nop:$slf4j_version" +} + +jar { + manifest { + attributes('Sealed': true) + } +} + +tasks.withType(Test) { + systemProperty 'deterministic-rt.path', configurations.jdkRt.asPath + systemProperty 'sandbox-libraries.path', configurations.sandboxTesting.asPath +} + +//publish { +// name 'corda-djvm-serialization' +//} + +idea { + module { + downloadJavadoc = true + downloadSources = true + } +} diff --git a/deserializers/build.gradle b/deserializers/build.gradle new file mode 100644 index 0000000000..d6a087a58f --- /dev/null +++ b/deserializers/build.gradle @@ -0,0 +1,29 @@ +plugins { + id 'org.jetbrains.kotlin.jvm' + id 'java-library' + id 'idea' +} + +description 'Deserializers for the DJVM' + +dependencies { + api "net.corda:corda-core:$corda_version" + api "net.corda:corda-serialization:$corda_version" +} + +jar { + manifest { + attributes('Sealed': true) + } +} + +//publish { +// name 'corda-djvm-deserializers' +//} + +idea { + module { + downloadJavadoc = true + downloadSources = true + } +} diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/BitSetDeserializer.kt b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/BitSetDeserializer.kt new file mode 100644 index 0000000000..3e8c77a844 --- /dev/null +++ b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/BitSetDeserializer.kt @@ -0,0 +1,11 @@ +package net.corda.djvm.serialization.deserializers + +import net.corda.serialization.internal.amqp.custom.BitSetSerializer.BitSetProxy +import java.util.* +import java.util.function.Function + +class BitSetDeserializer : Function { + override fun apply(proxy: BitSetProxy): BitSet { + return BitSet.valueOf(proxy.bytes) + } +} diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/CertPathDeserializer.kt b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/CertPathDeserializer.kt new file mode 100644 index 0000000000..8ccd55849f --- /dev/null +++ b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/CertPathDeserializer.kt @@ -0,0 +1,13 @@ +package net.corda.djvm.serialization.deserializers + +import net.corda.serialization.internal.amqp.custom.CertPathSerializer.CertPathProxy +import java.security.cert.CertPath +import java.security.cert.CertificateFactory +import java.util.function.Function + +class CertPathDeserializer : Function { + override fun apply(proxy: CertPathProxy): CertPath { + val factory = CertificateFactory.getInstance(proxy.type) + return factory.generateCertPath(proxy.encoded.inputStream()) + } +} diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/ClassDeserializer.kt b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/ClassDeserializer.kt new file mode 100644 index 0000000000..b3f44751cb --- /dev/null +++ b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/ClassDeserializer.kt @@ -0,0 +1,11 @@ +package net.corda.djvm.serialization.deserializers + +import net.corda.serialization.internal.amqp.custom.ClassSerializer.ClassProxy + +import java.util.function.Function + +class ClassDeserializer : Function> { + override fun apply(proxy: ClassProxy): Class<*> { + return Class.forName(proxy.className) + } +} diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/CreateCollection.kt b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/CreateCollection.kt new file mode 100644 index 0000000000..0a1cb0e8db --- /dev/null +++ b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/CreateCollection.kt @@ -0,0 +1,47 @@ +package net.corda.djvm.serialization.deserializers + +import net.corda.core.utilities.NonEmptySet +import java.util.* +import java.util.function.Function + +class CreateCollection : Function, Collection> { + private val concreteConstructors: Map>, (Array) -> Collection> = mapOf( + List::class.java to ::createList, + Set::class.java to ::createSet, + SortedSet::class.java to ::createSortedSet, + NavigableSet::class.java to ::createNavigableSet, + Collection::class.java to ::createCollection, + NonEmptySet::class.java to ::createNonEmptySet + ) + + private fun createList(values: Array): List { + return Collections.unmodifiableList(arrayListOf(*values)) + } + + private fun createSet(values: Array): Set { + return Collections.unmodifiableSet(linkedSetOf(*values)) + } + + private fun createSortedSet(values: Array): SortedSet { + return Collections.unmodifiableSortedSet(sortedSetOf(*values)) + } + + private fun createNavigableSet(values: Array): NavigableSet { + return Collections.unmodifiableNavigableSet(sortedSetOf(*values)) + } + + private fun createCollection(values: Array): Collection { + return Collections.unmodifiableCollection(arrayListOf(*values)) + } + + private fun createNonEmptySet(values: Array): NonEmptySet { + return NonEmptySet.copyOf(arrayListOf(*values)) + } + + @Suppress("unchecked_cast") + override fun apply(inputs: Array): Collection { + val collectionClass = inputs[0] as Class> + val args = inputs[1] as Array + return concreteConstructors[collectionClass]?.invoke(args)!! + } +} diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/CreateCurrency.kt b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/CreateCurrency.kt new file mode 100644 index 0000000000..51230b8372 --- /dev/null +++ b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/CreateCurrency.kt @@ -0,0 +1,10 @@ +package net.corda.djvm.serialization.deserializers + +import java.util.* +import java.util.function.Function + +class CreateCurrency : Function { + override fun apply(currencyCode: String): Currency { + return Currency.getInstance(currencyCode) + } +} diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/CreateFromString.kt b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/CreateFromString.kt new file mode 100644 index 0000000000..027858091b --- /dev/null +++ b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/CreateFromString.kt @@ -0,0 +1,10 @@ +package net.corda.djvm.serialization.deserializers + +import java.lang.reflect.Constructor +import java.util.function.Function + +class CreateFromString(private val factory: Constructor) : Function { + override fun apply(text: String): Any { + return factory.newInstance(text) + } +} diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/CreateMap.kt b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/CreateMap.kt new file mode 100644 index 0000000000..d22d0427d6 --- /dev/null +++ b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/CreateMap.kt @@ -0,0 +1,48 @@ +package net.corda.djvm.serialization.deserializers + +import java.util.* +import java.util.function.Function + +class CreateMap : Function, Map> { + private val concreteConstructors: Map>, (Array>) -> Map> = mapOf( + Map::class.java to ::createMap, + SortedMap::class.java to ::createSortedMap, + LinkedHashMap::class.java to ::createLinkedHashMap, + NavigableMap::class.java to ::createNavigableMap, + TreeMap::class.java to ::createTreeMap, + EnumMap::class.java to ::createEnumMap + ) + + private fun createMap(values: Array>): Map { + return Collections.unmodifiableMap(values.map { it[0] to it[1] }.toMap()) + } + + private fun createSortedMap(values: Array>): SortedMap { + return Collections.unmodifiableSortedMap(createTreeMap(values)) + } + + private fun createNavigableMap(values: Array>): NavigableMap { + return Collections.unmodifiableNavigableMap(createTreeMap(values)) + } + + private fun createLinkedHashMap(values: Array>): LinkedHashMap { + return values.map { it[0] to it[1] }.toMap(LinkedHashMap()) + } + + private fun createTreeMap(values: Array>): TreeMap { + return values.map { it[0] to it[1] }.toMap(TreeMap()) + } + + private fun createEnumMap(values: Array>): Map { + val map = values.map { it[0] to it[1] }.toMap() + @Suppress("unchecked_cast") + return EnumMap(map as Map) as Map + } + + @Suppress("unchecked_cast") + override fun apply(inputs: Array): Map { + val mapClass = inputs[0] as Class> + val args = inputs[1] as Array> + return concreteConstructors[mapClass]?.invoke(args)!! + } +} diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/Decimal128Deserializer.kt b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/Decimal128Deserializer.kt new file mode 100644 index 0000000000..065418cdbd --- /dev/null +++ b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/Decimal128Deserializer.kt @@ -0,0 +1,10 @@ +package net.corda.djvm.serialization.deserializers + +import org.apache.qpid.proton.amqp.Decimal128 +import java.util.function.Function + +class Decimal128Deserializer : Function { + override fun apply(underlying: LongArray): Decimal128 { + return Decimal128(underlying[0], underlying[1]) + } +} diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/Decimal32Deserializer.kt b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/Decimal32Deserializer.kt new file mode 100644 index 0000000000..3820329a41 --- /dev/null +++ b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/Decimal32Deserializer.kt @@ -0,0 +1,10 @@ +package net.corda.djvm.serialization.deserializers + +import org.apache.qpid.proton.amqp.Decimal32 +import java.util.function.Function + +class Decimal32Deserializer : Function { + override fun apply(underlying: IntArray): Decimal32 { + return Decimal32(underlying[0]) + } +} diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/Decimal64Deserializer.kt b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/Decimal64Deserializer.kt new file mode 100644 index 0000000000..4f298cb5e9 --- /dev/null +++ b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/Decimal64Deserializer.kt @@ -0,0 +1,10 @@ +package net.corda.djvm.serialization.deserializers + +import org.apache.qpid.proton.amqp.Decimal64 +import java.util.function.Function + +class Decimal64Deserializer : Function { + override fun apply(underlying: LongArray): Decimal64 { + return Decimal64(underlying[0]) + } +} diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/DescribeEnum.kt b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/DescribeEnum.kt new file mode 100644 index 0000000000..1d8d7e371e --- /dev/null +++ b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/DescribeEnum.kt @@ -0,0 +1,9 @@ +package net.corda.djvm.serialization.deserializers + +import java.util.function.Function + +class DescribeEnum : Function, Array> { + override fun apply(enumClass: Class<*>): Array { + return enumClass.enumConstants + } +} diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/DurationDeserializer.kt b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/DurationDeserializer.kt new file mode 100644 index 0000000000..7369932a0d --- /dev/null +++ b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/DurationDeserializer.kt @@ -0,0 +1,11 @@ +package net.corda.djvm.serialization.deserializers + +import net.corda.serialization.internal.amqp.custom.DurationSerializer.DurationProxy +import java.time.Duration +import java.util.function.Function + +class DurationDeserializer : Function { + override fun apply(proxy: DurationProxy): Duration { + return Duration.ofSeconds(proxy.seconds, proxy.nanos.toLong()) + } +} diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/EnumSetDeserializer.kt b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/EnumSetDeserializer.kt new file mode 100644 index 0000000000..510ee2b4b0 --- /dev/null +++ b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/EnumSetDeserializer.kt @@ -0,0 +1,16 @@ +package net.corda.djvm.serialization.deserializers + +import net.corda.core.internal.uncheckedCast +import net.corda.serialization.internal.amqp.custom.EnumSetSerializer.EnumSetProxy +import java.util.* +import java.util.function.Function + +class EnumSetDeserializer : Function> { + override fun apply(proxy: EnumSetProxy): EnumSet<*> { + return if (proxy.elements.isEmpty()) { + EnumSet.noneOf(uncheckedCast, Class>(proxy.clazz)) + } else { + EnumSet.copyOf(uncheckedCast, List>(proxy.elements)) + } + } +} diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/InstantDeserializer.kt b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/InstantDeserializer.kt new file mode 100644 index 0000000000..084495ee2b --- /dev/null +++ b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/InstantDeserializer.kt @@ -0,0 +1,11 @@ +package net.corda.djvm.serialization.deserializers + +import net.corda.serialization.internal.amqp.custom.InstantSerializer.InstantProxy +import java.time.Instant +import java.util.function.Function + +class InstantDeserializer : Function { + override fun apply(proxy: InstantProxy): Instant { + return Instant.ofEpochSecond(proxy.epochSeconds, proxy.nanos.toLong()) + } +} diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/JustForCasting.kt b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/JustForCasting.kt new file mode 100644 index 0000000000..17860c31c5 --- /dev/null +++ b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/JustForCasting.kt @@ -0,0 +1,6 @@ +package net.corda.djvm.serialization.deserializers + +@Suppress("unused") +enum class JustForCasting { + UNUSED +} diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/LocalDateDeserializer.kt b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/LocalDateDeserializer.kt new file mode 100644 index 0000000000..121298ae6b --- /dev/null +++ b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/LocalDateDeserializer.kt @@ -0,0 +1,11 @@ +package net.corda.djvm.serialization.deserializers + +import net.corda.serialization.internal.amqp.custom.LocalDateSerializer.LocalDateProxy +import java.time.LocalDate +import java.util.function.Function + +class LocalDateDeserializer : Function { + override fun apply(proxy: LocalDateProxy): LocalDate { + return LocalDate.of(proxy.year, proxy.month.toInt(), proxy.day.toInt()) + } +} diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/LocalDateTimeDeserializer.kt b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/LocalDateTimeDeserializer.kt new file mode 100644 index 0000000000..fd26c625b9 --- /dev/null +++ b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/LocalDateTimeDeserializer.kt @@ -0,0 +1,11 @@ +package net.corda.djvm.serialization.deserializers + +import net.corda.serialization.internal.amqp.custom.LocalDateTimeSerializer.LocalDateTimeProxy +import java.time.LocalDateTime +import java.util.function.Function + +class LocalDateTimeDeserializer : Function { + override fun apply(proxy: LocalDateTimeProxy): LocalDateTime { + return LocalDateTime.of(proxy.date, proxy.time) + } +} diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/LocalTimeDeserializer.kt b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/LocalTimeDeserializer.kt new file mode 100644 index 0000000000..f346333692 --- /dev/null +++ b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/LocalTimeDeserializer.kt @@ -0,0 +1,11 @@ +package net.corda.djvm.serialization.deserializers + +import net.corda.serialization.internal.amqp.custom.LocalTimeSerializer.LocalTimeProxy +import java.time.LocalTime +import java.util.function.Function + +class LocalTimeDeserializer : Function { + override fun apply(proxy: LocalTimeProxy): LocalTime { + return LocalTime.of(proxy.hour.toInt(), proxy.minute.toInt(), proxy.second.toInt(), proxy.nano) + } +} diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/MonthDayDeserializer.kt b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/MonthDayDeserializer.kt new file mode 100644 index 0000000000..4b5827b462 --- /dev/null +++ b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/MonthDayDeserializer.kt @@ -0,0 +1,11 @@ +package net.corda.djvm.serialization.deserializers + +import net.corda.serialization.internal.amqp.custom.MonthDaySerializer.MonthDayProxy +import java.time.MonthDay +import java.util.function.Function + +class MonthDayDeserializer : Function { + override fun apply(proxy: MonthDayProxy): MonthDay { + return MonthDay.of(proxy.month.toInt(), proxy.day.toInt()) + } +} diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/OffsetDateTimeDeserializer.kt b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/OffsetDateTimeDeserializer.kt new file mode 100644 index 0000000000..d91976ab67 --- /dev/null +++ b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/OffsetDateTimeDeserializer.kt @@ -0,0 +1,11 @@ +package net.corda.djvm.serialization.deserializers + +import net.corda.serialization.internal.amqp.custom.OffsetDateTimeSerializer.OffsetDateTimeProxy +import java.time.OffsetDateTime +import java.util.function.Function + +class OffsetDateTimeDeserializer : Function { + override fun apply(proxy: OffsetDateTimeProxy): OffsetDateTime { + return OffsetDateTime.of(proxy.dateTime, proxy.offset) + } +} diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/OffsetTimeDeserializer.kt b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/OffsetTimeDeserializer.kt new file mode 100644 index 0000000000..b668affce0 --- /dev/null +++ b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/OffsetTimeDeserializer.kt @@ -0,0 +1,11 @@ +package net.corda.djvm.serialization.deserializers + +import net.corda.serialization.internal.amqp.custom.OffsetTimeSerializer.OffsetTimeProxy +import java.time.OffsetTime +import java.util.function.Function + +class OffsetTimeDeserializer : Function { + override fun apply(proxy: OffsetTimeProxy): OffsetTime { + return OffsetTime.of(proxy.time, proxy.offset) + } +} diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/OptionalDeserializer.kt b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/OptionalDeserializer.kt new file mode 100644 index 0000000000..483757e3dd --- /dev/null +++ b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/OptionalDeserializer.kt @@ -0,0 +1,11 @@ +package net.corda.djvm.serialization.deserializers + +import net.corda.serialization.internal.amqp.custom.OptionalSerializer.OptionalProxy +import java.util.* +import java.util.function.Function + +class OptionalDeserializer : Function> { + override fun apply(proxy: OptionalProxy): Optional { + return Optional.ofNullable(proxy.item) + } +} diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/PeriodDeserializer.kt b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/PeriodDeserializer.kt new file mode 100644 index 0000000000..7b5100d5fd --- /dev/null +++ b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/PeriodDeserializer.kt @@ -0,0 +1,11 @@ +package net.corda.djvm.serialization.deserializers + +import net.corda.serialization.internal.amqp.custom.PeriodSerializer.PeriodProxy +import java.time.Period +import java.util.function.Function + +class PeriodDeserializer : Function { + override fun apply(proxy: PeriodProxy): Period { + return Period.of(proxy.years, proxy.months, proxy.days) + } +} diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/PublicKeyDecoder.kt b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/PublicKeyDecoder.kt new file mode 100644 index 0000000000..9c27dde405 --- /dev/null +++ b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/PublicKeyDecoder.kt @@ -0,0 +1,11 @@ +package net.corda.djvm.serialization.deserializers + +import net.corda.core.crypto.Crypto +import java.security.PublicKey +import java.util.function.Function + +class PublicKeyDecoder : Function { + override fun apply(encoded: ByteArray): PublicKey { + return Crypto.decodePublicKey(encoded) + } +} diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/SymbolDeserializer.kt b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/SymbolDeserializer.kt new file mode 100644 index 0000000000..63833392b3 --- /dev/null +++ b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/SymbolDeserializer.kt @@ -0,0 +1,10 @@ +package net.corda.djvm.serialization.deserializers + +import org.apache.qpid.proton.amqp.Symbol +import java.util.function.Function + +class SymbolDeserializer : Function { + override fun apply(value: String): Symbol { + return Symbol.valueOf(value) + } +} diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/UnsignedByteDeserializer.kt b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/UnsignedByteDeserializer.kt new file mode 100644 index 0000000000..3e32c25787 --- /dev/null +++ b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/UnsignedByteDeserializer.kt @@ -0,0 +1,10 @@ +package net.corda.djvm.serialization.deserializers + +import org.apache.qpid.proton.amqp.UnsignedByte +import java.util.function.Function + +class UnsignedByteDeserializer : Function { + override fun apply(underlying: ByteArray): UnsignedByte { + return UnsignedByte(underlying[0]) + } +} diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/UnsignedIntegerDeserializer.kt b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/UnsignedIntegerDeserializer.kt new file mode 100644 index 0000000000..7424430ff1 --- /dev/null +++ b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/UnsignedIntegerDeserializer.kt @@ -0,0 +1,10 @@ +package net.corda.djvm.serialization.deserializers + +import org.apache.qpid.proton.amqp.UnsignedInteger +import java.util.function.Function + +class UnsignedIntegerDeserializer : Function { + override fun apply(underlying: IntArray): UnsignedInteger { + return UnsignedInteger(underlying[0]) + } +} diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/UnsignedLongDeserializer.kt b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/UnsignedLongDeserializer.kt new file mode 100644 index 0000000000..0ef378abec --- /dev/null +++ b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/UnsignedLongDeserializer.kt @@ -0,0 +1,10 @@ +package net.corda.djvm.serialization.deserializers + +import org.apache.qpid.proton.amqp.UnsignedLong +import java.util.function.Function + +class UnsignedLongDeserializer : Function { + override fun apply(underlying: LongArray): UnsignedLong { + return UnsignedLong(underlying[0]) + } +} diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/UnsignedShortDeserializer.kt b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/UnsignedShortDeserializer.kt new file mode 100644 index 0000000000..2f38994378 --- /dev/null +++ b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/UnsignedShortDeserializer.kt @@ -0,0 +1,10 @@ +package net.corda.djvm.serialization.deserializers + +import org.apache.qpid.proton.amqp.UnsignedShort +import java.util.function.Function + +class UnsignedShortDeserializer : Function { + override fun apply(underlying: ShortArray): UnsignedShort { + return UnsignedShort(underlying[0]) + } +} diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/X509CRLDeserializer.kt b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/X509CRLDeserializer.kt new file mode 100644 index 0000000000..5e4b9b8e7c --- /dev/null +++ b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/X509CRLDeserializer.kt @@ -0,0 +1,12 @@ +package net.corda.djvm.serialization.deserializers + +import java.security.cert.CertificateFactory +import java.security.cert.X509CRL +import java.util.function.Function + +class X509CRLDeserializer : Function { + override fun apply(bytes: ByteArray): X509CRL { + val factory = CertificateFactory.getInstance("X.509") + return factory.generateCRL(bytes.inputStream()) as X509CRL + } +} diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/X509CertificateDeserializer.kt b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/X509CertificateDeserializer.kt new file mode 100644 index 0000000000..1cbd2f7491 --- /dev/null +++ b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/X509CertificateDeserializer.kt @@ -0,0 +1,12 @@ +package net.corda.djvm.serialization.deserializers + +import java.security.cert.CertificateFactory +import java.security.cert.X509Certificate +import java.util.function.Function + +class X509CertificateDeserializer : Function { + override fun apply(bits: ByteArray): X509Certificate { + val factory = CertificateFactory.getInstance("X.509") + return factory.generateCertificate(bits.inputStream()) as X509Certificate + } +} diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/YearDeserializer.kt b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/YearDeserializer.kt new file mode 100644 index 0000000000..d259c0a95a --- /dev/null +++ b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/YearDeserializer.kt @@ -0,0 +1,11 @@ +package net.corda.djvm.serialization.deserializers + +import net.corda.serialization.internal.amqp.custom.YearSerializer.YearProxy +import java.time.Year +import java.util.function.Function + +class YearDeserializer : Function { + override fun apply(proxy: YearProxy): Year { + return Year.of(proxy.year) + } +} diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/YearMonthDeserializer.kt b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/YearMonthDeserializer.kt new file mode 100644 index 0000000000..31cb123d8f --- /dev/null +++ b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/YearMonthDeserializer.kt @@ -0,0 +1,11 @@ +package net.corda.djvm.serialization.deserializers + +import net.corda.serialization.internal.amqp.custom.YearMonthSerializer.YearMonthProxy +import java.time.YearMonth +import java.util.function.Function + +class YearMonthDeserializer : Function { + override fun apply(proxy: YearMonthProxy): YearMonth { + return YearMonth.of(proxy.year, proxy.month.toInt()) + } +} diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/ZoneIdDeserializer.kt b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/ZoneIdDeserializer.kt new file mode 100644 index 0000000000..b0e64c6e7d --- /dev/null +++ b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/ZoneIdDeserializer.kt @@ -0,0 +1,11 @@ +package net.corda.djvm.serialization.deserializers + +import net.corda.serialization.internal.amqp.custom.ZoneIdSerializer.ZoneIdProxy +import java.time.ZoneId +import java.util.function.Function + +class ZoneIdDeserializer : Function { + override fun apply(proxy: ZoneIdProxy): ZoneId { + return ZoneId.of(proxy.id) + } +} diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/ZonedDateTimeDeserializer.kt b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/ZonedDateTimeDeserializer.kt new file mode 100644 index 0000000000..3ac0744283 --- /dev/null +++ b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/ZonedDateTimeDeserializer.kt @@ -0,0 +1,10 @@ +package net.corda.djvm.serialization.deserializers + +import net.corda.serialization.internal.amqp.custom.ZonedDateTimeSerializer.ZonedDateTimeProxy +import java.util.function.Function + +class ZonedDateTimeDeserializer : Function?> { + override fun apply(proxy: ZonedDateTimeProxy): Array? { + return arrayOf(proxy.dateTime, proxy.offset, proxy.zone) + } +} diff --git a/src/main/kotlin/net/corda/djvm/serialization/AMQPSerializationScheme.kt b/src/main/kotlin/net/corda/djvm/serialization/AMQPSerializationScheme.kt new file mode 100644 index 0000000000..90981d486a --- /dev/null +++ b/src/main/kotlin/net/corda/djvm/serialization/AMQPSerializationScheme.kt @@ -0,0 +1,89 @@ +package net.corda.djvm.serialization + +import net.corda.core.serialization.SerializationContext +import net.corda.core.serialization.SerializationContext.UseCase +import net.corda.core.serialization.SerializedBytes +import net.corda.core.utilities.ByteSequence +import net.corda.djvm.rewiring.SandboxClassLoader +import net.corda.djvm.serialization.serializers.* +import net.corda.serialization.internal.CordaSerializationMagic +import net.corda.serialization.internal.SerializationScheme +import net.corda.serialization.internal.amqp.* +import java.math.BigDecimal +import java.math.BigInteger +import java.util.* +import java.util.function.BiFunction +import java.util.function.Function + +class AMQPSerializationScheme( + private val classLoader: SandboxClassLoader, + private val sandboxBasicInput: Function, + private val executor: BiFunction, + private val serializerFactoryFactory: SerializerFactoryFactory +) : SerializationScheme { + + private fun getSerializerFactory(context: SerializationContext): SerializerFactory { + return serializerFactoryFactory.make(context).apply { + register(SandboxBitSetSerializer(classLoader, executor, this)) + register(SandboxCertPathSerializer(classLoader, executor, this)) + register(SandboxDurationSerializer(classLoader, executor, this)) + register(SandboxEnumSetSerializer(classLoader, executor, this)) + register(SandboxInstantSerializer(classLoader, executor, this)) + register(SandboxLocalDateSerializer(classLoader, executor, this)) + register(SandboxLocalDateTimeSerializer(classLoader, executor, this)) + register(SandboxLocalTimeSerializer(classLoader, executor, this)) + register(SandboxMonthDaySerializer(classLoader, executor, this)) + register(SandboxOffsetDateTimeSerializer(classLoader, executor, this)) + register(SandboxOffsetTimeSerializer(classLoader, executor, this)) + register(SandboxPeriodSerializer(classLoader, executor, this)) + register(SandboxYearMonthSerializer(classLoader, executor, this)) + register(SandboxYearSerializer(classLoader, executor, this)) + register(SandboxZonedDateTimeSerializer(classLoader, executor, this)) + register(SandboxZoneIdSerializer(classLoader, executor, this)) + register(SandboxOptionalSerializer(classLoader, executor, this)) + register(SandboxPrimitiveSerializer(UUID::class.java, classLoader, sandboxBasicInput)) + register(SandboxPrimitiveSerializer(String::class.java, classLoader, sandboxBasicInput)) + register(SandboxPrimitiveSerializer(Byte::class.javaObjectType, classLoader, sandboxBasicInput)) + register(SandboxPrimitiveSerializer(Short::class.javaObjectType, classLoader, sandboxBasicInput)) + register(SandboxPrimitiveSerializer(Int::class.javaObjectType, classLoader, sandboxBasicInput)) + register(SandboxPrimitiveSerializer(Long::class.javaObjectType, classLoader, sandboxBasicInput)) + register(SandboxPrimitiveSerializer(Float::class.javaObjectType, classLoader, sandboxBasicInput)) + register(SandboxPrimitiveSerializer(Double::class.javaObjectType, classLoader, sandboxBasicInput)) + register(SandboxPrimitiveSerializer(Boolean::class.javaObjectType, classLoader, sandboxBasicInput)) + register(SandboxPrimitiveSerializer(Date::class.javaObjectType, classLoader, sandboxBasicInput)) + register(SandboxCharacterSerializer(classLoader, sandboxBasicInput)) + register(SandboxCollectionSerializer(classLoader, executor, this)) + register(SandboxMapSerializer(classLoader, executor, this)) + register(SandboxEnumSerializer(classLoader, executor, this)) + register(SandboxPublicKeySerializer(classLoader, executor)) + register(SandboxToStringSerializer(BigDecimal::class.java, classLoader, executor, sandboxBasicInput)) + register(SandboxToStringSerializer(BigInteger::class.java, classLoader, executor, sandboxBasicInput)) + register(SandboxToStringSerializer(StringBuffer::class.java, classLoader, executor, sandboxBasicInput)) + register(SandboxCurrencySerializer(classLoader, executor, sandboxBasicInput)) + register(SandboxX509CertificateSerializer(classLoader, executor)) + register(SandboxX509CRLSerializer(classLoader, executor)) + register(SandboxUnsignedLongSerializer(classLoader, executor)) + register(SandboxUnsignedIntegerSerializer(classLoader, executor)) + register(SandboxUnsignedShortSerializer(classLoader, executor)) + register(SandboxUnsignedByteSerializer(classLoader, executor)) + register(SandboxDecimal128Serializer(classLoader, executor)) + register(SandboxDecimal64Serializer(classLoader, executor)) + register(SandboxDecimal32Serializer(classLoader, executor)) + register(SandboxSymbolSerializer(classLoader, executor, sandboxBasicInput)) + } + } + + override fun deserialize(byteSequence: ByteSequence, clazz: Class, context: SerializationContext): T { + val serializerFactory = getSerializerFactory(context) + return DeserializationInput(serializerFactory).deserialize(byteSequence, clazz, context) + } + + override fun serialize(obj: T, context: SerializationContext): SerializedBytes { + val serializerFactory = getSerializerFactory(context) + return SerializationOutput(serializerFactory).serialize(obj, context) + } + + override fun canDeserializeVersion(magic: CordaSerializationMagic, target: UseCase): Boolean { + return magic == amqpMagic && target == UseCase.P2P + } +} diff --git a/src/main/kotlin/net/corda/djvm/serialization/DelegatingClassLoader.kt b/src/main/kotlin/net/corda/djvm/serialization/DelegatingClassLoader.kt new file mode 100644 index 0000000000..2d530d08f9 --- /dev/null +++ b/src/main/kotlin/net/corda/djvm/serialization/DelegatingClassLoader.kt @@ -0,0 +1,10 @@ +package net.corda.djvm.serialization + +import net.corda.djvm.rewiring.SandboxClassLoader + +class DelegatingClassLoader(private val delegate: SandboxClassLoader) : ClassLoader(null) { + @Throws(ClassNotFoundException::class) + override fun loadClass(name: String, resolve: Boolean): Class<*> { + return delegate.loadForSandbox(name).type + } +} diff --git a/src/main/kotlin/net/corda/djvm/serialization/SandboxSerializerFactoryFactory.kt b/src/main/kotlin/net/corda/djvm/serialization/SandboxSerializerFactoryFactory.kt new file mode 100644 index 0000000000..442a3265ca --- /dev/null +++ b/src/main/kotlin/net/corda/djvm/serialization/SandboxSerializerFactoryFactory.kt @@ -0,0 +1,85 @@ +@file:Suppress("platform_class_mapped_to_kotlin") +package net.corda.djvm.serialization + +import net.corda.core.serialization.SerializationContext +import net.corda.serialization.internal.amqp.* +import net.corda.serialization.internal.model.* +import java.lang.Boolean +import java.lang.Byte +import java.lang.Double +import java.lang.Float +import java.lang.Long +import java.lang.Short +import java.util.Collections.singleton +import java.util.Collections.unmodifiableMap +import java.util.function.Function + +/** + * This has all been lovingly copied from [SerializerFactoryBuilder]. + */ +class SandboxSerializerFactoryFactory( + private val primitiveSerializerFactory: Function, AMQPSerializer> +) : SerializerFactoryFactory { + + override fun make(context: SerializationContext): SerializerFactory { + val classLoader = context.deserializationClassLoader + + val primitiveTypes = unmodifiableMap(mapOf, Class<*>>( + classLoader.loadClass("sandbox.java.lang.Boolean") to Boolean.TYPE, + classLoader.loadClass("sandbox.java.lang.Byte") to Byte.TYPE, + classLoader.loadClass("sandbox.java.lang.Character") to Character.TYPE, + classLoader.loadClass("sandbox.java.lang.Double") to Double.TYPE, + classLoader.loadClass("sandbox.java.lang.Float") to Float.TYPE, + classLoader.loadClass("sandbox.java.lang.Integer") to Integer.TYPE, + classLoader.loadClass("sandbox.java.lang.Long") to Long.TYPE, + classLoader.loadClass("sandbox.java.lang.Short") to Short.TYPE + )) + + val classCarpenter = createClassCarpenter(context) + val descriptorBasedSerializerRegistry = DefaultDescriptorBasedSerializerRegistry() + val customSerializerRegistry = CachingCustomSerializerRegistry( + descriptorBasedSerializerRegistry = descriptorBasedSerializerRegistry, + allowedFor = singleton(classLoader.loadClass("sandbox.java.lang.Object")) + ) + + val localTypeModel = ConfigurableLocalTypeModel( + WhitelistBasedTypeModelConfiguration(context.whitelist, customSerializerRegistry) + ) + + val fingerPrinter = TypeModellingFingerPrinter(customSerializerRegistry) + + val localSerializerFactory = DefaultLocalSerializerFactory( + whitelist = context.whitelist, + typeModel = localTypeModel, + fingerPrinter = fingerPrinter, + classloader = classLoader, + descriptorBasedSerializerRegistry = descriptorBasedSerializerRegistry, + primitiveSerializerFactory = primitiveSerializerFactory, + customSerializerRegistry = customSerializerRegistry, + onlyCustomSerializers = false + ) + + val typeLoader: TypeLoader = ClassCarpentingTypeLoader( + carpenter = SchemaBuildingRemoteTypeCarpenter(classCarpenter), + classLoader = classLoader + ) + + val evolutionSerializerFactory = DefaultEvolutionSerializerFactory( + localSerializerFactory = localSerializerFactory, + classLoader = classLoader, + mustPreserveDataWhenEvolving = context.preventDataLoss, + primitiveTypes = primitiveTypes + ) + + val remoteSerializerFactory = DefaultRemoteSerializerFactory( + evolutionSerializerFactory = evolutionSerializerFactory, + descriptorBasedSerializerRegistry = descriptorBasedSerializerRegistry, + remoteTypeModel = AMQPRemoteTypeModel(), + localTypeModel = localTypeModel, + typeLoader = typeLoader, + localSerializerFactory = localSerializerFactory + ) + + return ComposedSerializerFactory(localSerializerFactory, remoteSerializerFactory, customSerializerRegistry) + } +} diff --git a/src/main/kotlin/net/corda/djvm/serialization/SandboxWhitelist.kt b/src/main/kotlin/net/corda/djvm/serialization/SandboxWhitelist.kt new file mode 100644 index 0000000000..12c21a2c65 --- /dev/null +++ b/src/main/kotlin/net/corda/djvm/serialization/SandboxWhitelist.kt @@ -0,0 +1,13 @@ +package net.corda.djvm.serialization + +import net.corda.core.serialization.ClassWhitelist + +class SandboxWhitelist : ClassWhitelist { + companion object { + private val packageName = "^sandbox\\.(?:java|kotlin)(?:[.]|$)".toRegex() + } + + override fun hasListed(type: Class<*>): Boolean { + return packageName.containsMatchIn(type.`package`.name) + } +} diff --git a/src/main/kotlin/net/corda/djvm/serialization/Serialization.kt b/src/main/kotlin/net/corda/djvm/serialization/Serialization.kt new file mode 100644 index 0000000000..8e1f16d4a4 --- /dev/null +++ b/src/main/kotlin/net/corda/djvm/serialization/Serialization.kt @@ -0,0 +1,87 @@ +@file:JvmName("Serialization") +package net.corda.djvm.serialization + +import net.corda.core.serialization.SerializationContext +import net.corda.core.serialization.SerializationContext.UseCase +import net.corda.core.serialization.SerializationFactory +import net.corda.core.serialization.SerializedBytes +import net.corda.core.serialization.internal.SerializationEnvironment +import net.corda.djvm.execution.SandboxRuntimeException +import net.corda.djvm.rewiring.SandboxClassLoader +import net.corda.djvm.serialization.serializers.PrimitiveSerializer +import net.corda.djvm.source.ClassSource +import net.corda.serialization.internal.GlobalTransientClassWhiteList +import net.corda.serialization.internal.SerializationContextImpl +import net.corda.serialization.internal.SerializationFactoryImpl +import net.corda.serialization.internal.amqp.AMQPSerializer +import net.corda.serialization.internal.amqp.amqpMagic +import java.lang.reflect.InvocationTargetException +import java.util.function.BiFunction +import java.util.function.Function + +fun SandboxClassLoader.loadClassForSandbox(clazz: Class<*>): Class { + @Suppress("unchecked_cast") + return loadClassForSandbox(ClassSource.fromClassName(clazz.name)) as Class +} + +fun createSandboxSerializationEnv(classLoader: SandboxClassLoader): SerializationEnvironment { + val p2pContext: SerializationContext = SerializationContextImpl( + preferredSerializationVersion = amqpMagic, + deserializationClassLoader = DelegatingClassLoader(classLoader), + whitelist = GlobalTransientClassWhiteList(SandboxWhitelist()), + properties = emptyMap(), + objectReferencesEnabled = true, + carpenterDisabled = true, + useCase = UseCase.P2P, + encoding = null + ) + + val taskClass = classLoader.loadClass("sandbox.RawTask") + val taskApply = taskClass.getDeclaredMethod("apply", Any::class.java) + val taskConstructor = taskClass.getDeclaredConstructor(classLoader.loadClassForSandbox(Function::class.java)) + val executor: BiFunction = BiFunction { userTask, arg -> + try { + taskApply(taskConstructor.newInstance(userTask), arg) + } catch (ex: InvocationTargetException) { + val target = ex.targetException + throw when (target) { + is RuntimeException, is Error -> target + else -> SandboxRuntimeException(target.message, target) + } + } + } + + val sandboxBasicInput = classLoader.createBasicInput() + + val primitiveSerializerFactory: Function, AMQPSerializer> = Function { clazz -> + PrimitiveSerializer(clazz, sandboxBasicInput) + } + + val factory = SerializationFactoryImpl(mutableMapOf()).apply { + registerScheme(AMQPSerializationScheme( + classLoader = classLoader, + sandboxBasicInput = sandboxBasicInput, + executor = executor, + serializerFactoryFactory = SandboxSerializerFactoryFactory(primitiveSerializerFactory) + )) + } + return SerializationEnvironment.with(factory, p2pContext = p2pContext) +} + +inline fun SerializedBytes.deserializeFor(classLoader: SandboxClassLoader): Any { + val clazz = classLoader.loadClassForSandbox(T::class.java) + return deserializeTo(clazz, classLoader) +} + +fun SerializedBytes<*>.deserializeTo(clazz: Class<*>, classLoader: SandboxClassLoader): Any { + return deserializeTo(clazz, classLoader, SerializationFactory.defaultFactory) +} + +fun SerializedBytes<*>.deserializeTo(clazz: Class<*>, classLoader: SandboxClassLoader, factory: SerializationFactory): Any { + val obj = factory.deserialize(this, Any::class.java, factory.defaultContext) + return if (clazz.isInstance(obj)) { + obj + } else { + classLoader.createBasicInput().apply(obj)!! + } +} diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/ExceptionUtils.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/ExceptionUtils.kt new file mode 100644 index 0000000000..2ec59cc99d --- /dev/null +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/ExceptionUtils.kt @@ -0,0 +1,38 @@ +@file:JvmName("ExceptionUtils") +package net.corda.djvm.serialization.serializers + +import net.corda.serialization.internal.amqp.AMQPNotSerializableException + +/** + * Utility function which helps tracking the path in the object graph when exceptions are thrown. + * Since there might be a chain of nested calls it is useful to record which part of the graph caused an issue. + * Path information is added to the message of the exception being thrown. + */ +internal inline fun ifThrowsAppend(strToAppendFn: () -> String, block: () -> T): T { + try { + return block() + } catch (th: Throwable) { + when (th) { + is AMQPNotSerializableException -> th.classHierarchy.add(strToAppendFn()) + // Do not overwrite the message of these exceptions as it may be used. + is ClassNotFoundException -> {} + is NoClassDefFoundError -> {} + else -> th.resetMessage("${strToAppendFn()} -> ${th.message}") + } + throw th + } +} + +/** + * Not a public property so will have to use reflection + */ +private fun Throwable.resetMessage(newMsg: String) { + val detailMessageField = Throwable::class.java.getDeclaredField("detailMessage") + detailMessageField.isAccessible = true + detailMessageField.set(this, newMsg) +} + +/** + * We currently only support deserialisation, and so we're going to need this. + */ +fun abortReadOnly(): Nothing = throw UnsupportedOperationException("Read Only!") \ No newline at end of file diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/PrimitiveSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/PrimitiveSerializer.kt new file mode 100644 index 0000000000..bd70965e3c --- /dev/null +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/PrimitiveSerializer.kt @@ -0,0 +1,28 @@ +package net.corda.djvm.serialization.serializers + +import net.corda.core.serialization.SerializationContext +import net.corda.serialization.internal.amqp.* +import org.apache.qpid.proton.amqp.Binary +import org.apache.qpid.proton.amqp.Symbol +import org.apache.qpid.proton.codec.Data +import java.lang.reflect.Type +import java.util.function.Function + +class PrimitiveSerializer( + override val type: Class<*>, + private val sandboxBasicInput: Function +) : AMQPSerializer { + override val typeDescriptor: Symbol = typeDescriptorFor(type) + + override fun readObject(obj: Any, schemas: SerializationSchemas, input: DeserializationInput, context: SerializationContext): Any { + return (obj as? Binary)?.array ?: sandboxBasicInput.apply(obj)!! + } + + override fun writeClassInfo(output: SerializationOutput) { + abortReadOnly() + } + + override fun writeObject(obj: Any, data: Data, type: Type, output: SerializationOutput, context: SerializationContext, debugIndent: Int) { + abortReadOnly() + } +} diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxBitSetSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxBitSetSerializer.kt new file mode 100644 index 0000000000..b6a2791944 --- /dev/null +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxBitSetSerializer.kt @@ -0,0 +1,31 @@ +package net.corda.djvm.serialization.serializers + +import net.corda.djvm.rewiring.SandboxClassLoader +import net.corda.djvm.serialization.deserializers.BitSetDeserializer +import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.serialization.internal.amqp.CustomSerializer +import net.corda.serialization.internal.amqp.SerializerFactory +import net.corda.serialization.internal.amqp.custom.BitSetSerializer.BitSetProxy +import java.util.* +import java.util.Collections.singleton +import java.util.function.BiFunction + +class SandboxBitSetSerializer( + classLoader: SandboxClassLoader, + private val executor: BiFunction, + factory: SerializerFactory +) : CustomSerializer.Proxy( + clazz = classLoader.loadClassForSandbox(BitSet::class.java), + proxyClass = classLoader.loadClassForSandbox(BitSetProxy::class.java), + factory = factory +) { + private val task = classLoader.loadClassForSandbox(BitSetDeserializer::class.java).newInstance() + + override val deserializationAliases: Set> = singleton(BitSet::class.java) + + override fun toProxy(obj: Any): Any = abortReadOnly() + + override fun fromProxy(proxy: Any): Any { + return executor.apply(task, proxy)!! + } +} diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCertPathSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCertPathSerializer.kt new file mode 100644 index 0000000000..e7380aaeaf --- /dev/null +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCertPathSerializer.kt @@ -0,0 +1,31 @@ +package net.corda.djvm.serialization.serializers + +import net.corda.djvm.rewiring.SandboxClassLoader +import net.corda.djvm.serialization.deserializers.CertPathDeserializer +import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.serialization.internal.amqp.CustomSerializer +import net.corda.serialization.internal.amqp.SerializerFactory +import net.corda.serialization.internal.amqp.custom.CertPathSerializer.CertPathProxy +import java.security.cert.CertPath +import java.util.Collections.singleton +import java.util.function.BiFunction + +class SandboxCertPathSerializer( + classLoader: SandboxClassLoader, + private val executor: BiFunction, + factory: SerializerFactory +) : CustomSerializer.Proxy( + clazz = classLoader.loadClassForSandbox(CertPath::class.java), + proxyClass = classLoader.loadClassForSandbox(CertPathProxy::class.java), + factory = factory +) { + private val task = classLoader.loadClassForSandbox(CertPathDeserializer::class.java).newInstance() + + override val deserializationAliases: Set> = singleton(CertPath::class.java) + + override fun toProxy(obj: Any): Any = abortReadOnly() + + override fun fromProxy(proxy: Any): Any { + return executor.apply(task, proxy)!! + } +} diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCharacterSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCharacterSerializer.kt new file mode 100644 index 0000000000..3793808587 --- /dev/null +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCharacterSerializer.kt @@ -0,0 +1,33 @@ +package net.corda.djvm.serialization.serializers + +import net.corda.core.serialization.SerializationContext +import net.corda.djvm.rewiring.SandboxClassLoader +import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.serialization.internal.amqp.* +import org.apache.qpid.proton.codec.Data +import java.lang.reflect.Type +import java.util.function.Function + +class SandboxCharacterSerializer( + classLoader: SandboxClassLoader, + private val basicInput: Function +) : CustomSerializer.Is(classLoader.loadClassForSandbox(Char::class.javaObjectType)) { + + override val schemaForDocumentation: Schema = Schema(emptyList()) + + override fun readObject(obj: Any, schemas: SerializationSchemas, input: DeserializationInput, context: SerializationContext): Any { + return basicInput.apply(convertToChar(obj))!! + } + + private fun convertToChar(obj: Any): Any { + return when (obj) { + is Short -> obj.toChar() + is Int -> obj.toChar() + else -> obj + } + } + + override fun writeDescribedObject(obj: Any, data: Data, type: Type, output: SerializationOutput, context: SerializationContext) { + abortReadOnly() + } +} diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxClassSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxClassSerializer.kt new file mode 100644 index 0000000000..28b275a62a --- /dev/null +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxClassSerializer.kt @@ -0,0 +1,54 @@ +package net.corda.djvm.serialization.serializers + +import net.corda.djvm.execution.SandboxRuntimeException +import net.corda.djvm.rewiring.SandboxClassLoader +import net.corda.djvm.serialization.deserializers.ClassDeserializer +import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.serialization.internal.amqp.AMQPNotSerializableException +import net.corda.serialization.internal.amqp.CustomSerializer +import net.corda.serialization.internal.amqp.SerializerFactory +import net.corda.serialization.internal.amqp.custom.ClassSerializer.ClassProxy +import java.util.function.BiFunction +import java.util.function.Function + +@Suppress("unchecked_cast") +class SandboxClassSerializer( + classLoader: SandboxClassLoader, + private val executor: BiFunction, + factory: SerializerFactory +) : CustomSerializer.Proxy( + clazz = Class::class.java as Class, + proxyClass = classLoader.loadClassForSandbox(ClassProxy::class.java), + factory = factory +) { + private val task = classLoader.loadClassForSandbox(ClassDeserializer::class.java).newInstance() + private val nameOf: Function + + init { + val fetch = proxyClass.getMethod("getClassName") + nameOf = Function { proxy -> + fetch(proxy).toString() + } + } + + override fun toProxy(obj: Any): Any = abortReadOnly() + + override fun fromProxy(proxy: Any): Any { + return try { + executor.apply(task, proxy)!! + } catch (e: SandboxRuntimeException) { + val cause = e.cause ?: throw e + if (cause !is ClassNotFoundException) { + throw cause + } + + val className = nameOf.apply(proxy) + throw AMQPNotSerializableException(type, + "Could not instantiate $className - not on the classpath", + "$className was not found by the node, check the Node containing the CorDapp that " + + "implements $className is loaded and on the Classpath", + mutableListOf(className) + ) + } + } +} diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCollectionSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCollectionSerializer.kt new file mode 100644 index 0000000000..3aad78113f --- /dev/null +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCollectionSerializer.kt @@ -0,0 +1,120 @@ +package net.corda.djvm.serialization.serializers + +import net.corda.core.serialization.SerializationContext +import net.corda.core.utilities.NonEmptySet +import net.corda.djvm.rewiring.SandboxClassLoader +import net.corda.djvm.serialization.deserializers.CreateCollection +import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.serialization.internal.amqp.* +import net.corda.serialization.internal.model.LocalTypeInformation +import net.corda.serialization.internal.model.TypeIdentifier +import org.apache.qpid.proton.amqp.Symbol +import org.apache.qpid.proton.codec.Data +import java.lang.reflect.ParameterizedType +import java.lang.reflect.Type +import java.util.* +import java.util.function.BiFunction +import java.util.function.Function + +class SandboxCollectionSerializer( + classLoader: SandboxClassLoader, + executor: BiFunction, + private val localFactory: LocalSerializerFactory +) : CustomSerializer.Implements(clazz = classLoader.loadClassForSandbox(Collection::class.java)) { + private val creator: Function, out Any?> + + init { + val createTask = classLoader.loadClassForSandbox(CreateCollection::class.java).newInstance() + creator = Function { inputs -> + executor.apply(createTask, inputs) + } + } + + private val unsupportedTypes: Set> = listOf( + EnumSet::class.java + ).map { + classLoader.loadClassForSandbox(it) + }.toSet() + + // The order matters here - the first match should be the most specific one. + // Kotlin preserves the ordering for us by associating into a LinkedHashMap. + private val supportedTypes: Map, Class>> = listOf( + List::class.java, + NonEmptySet::class.java, + NavigableSet::class.java, + SortedSet::class.java, + Set::class.java, + Collection::class.java + ).associateBy { + classLoader.loadClassForSandbox(it) + } + + private fun getBestMatchFor(type: Class): Map.Entry, Class>> + = supportedTypes.entries.first { it.key.isAssignableFrom(type) } + + override val schemaForDocumentation: Schema = Schema(emptyList()) + + override fun isSerializerFor(clazz: Class<*>): Boolean { + return super.isSerializerFor(clazz) && unsupportedTypes.none { it.isAssignableFrom(clazz) } + } + + override fun specialiseFor(declaredType: Type): AMQPSerializer? { + if (declaredType !is ParameterizedType) { + return null + } + + @Suppress("unchecked_cast") + val rawType = declaredType.rawType as Class + return ConcreteCollectionSerializer(declaredType, getBestMatchFor(rawType), creator, localFactory) + } + + override fun readObject(obj: Any, schemas: SerializationSchemas, input: DeserializationInput, context: SerializationContext): Any { + throw UnsupportedOperationException("Factory only") + } + + override fun writeDescribedObject(obj: Any, data: Data, type: Type, output: SerializationOutput, context: SerializationContext) { + throw UnsupportedOperationException("Factory Only") + } +} + +private class ConcreteCollectionSerializer( + declaredType: ParameterizedType, + private val matchingType: Map.Entry, Class>>, + private val creator: Function, out Any?>, + factory: LocalSerializerFactory +) : AMQPSerializer { + override val type: ParameterizedType = declaredType + + override val typeDescriptor: Symbol by lazy { + factory.createDescriptor( + LocalTypeInformation.ACollection( + observedType = declaredType.rawType, + typeIdentifier = TypeIdentifier.forGenericType(declaredType), + elementType =factory.getTypeInformation(declaredType.actualTypeArguments[0]) + ) + ) + } + + override fun readObject( + obj: Any, + schemas: SerializationSchemas, + input: DeserializationInput, + context: SerializationContext + ): Any { + val inboundType = type.actualTypeArguments[0] + return ifThrowsAppend({ type.typeName }) { + val args = (obj as List<*>).map { + input.readObjectOrNull(redescribe(it, inboundType), schemas, inboundType, context) + }.toTypedArray() + creator.apply(arrayOf(matchingType.key, args))!! + } + } + + override fun writeClassInfo(output: SerializationOutput) { + abortReadOnly() + } + + override fun writeObject(obj: Any, data: Data, type: Type, output: SerializationOutput, context: SerializationContext, debugIndent: Int) { + abortReadOnly() + } +} diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCurrencySerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCurrencySerializer.kt new file mode 100644 index 0000000000..9eee16cb33 --- /dev/null +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCurrencySerializer.kt @@ -0,0 +1,39 @@ +package net.corda.djvm.serialization.serializers + +import net.corda.core.serialization.SerializationContext +import net.corda.djvm.rewiring.SandboxClassLoader +import net.corda.djvm.serialization.deserializers.CreateCurrency +import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.serialization.internal.amqp.* +import org.apache.qpid.proton.codec.Data +import java.lang.reflect.Type +import java.util.* +import java.util.function.BiFunction +import java.util.function.Function + +class SandboxCurrencySerializer( + classLoader: SandboxClassLoader, + executor: BiFunction, + basicInput: Function +) : CustomSerializer.Is(classLoader.loadClassForSandbox(Currency::class.java)) { + private val creator: Function + + init { + val createTask = classLoader.loadClassForSandbox(CreateCurrency::class.java).newInstance() + creator = basicInput.andThen { input -> + executor.apply(createTask, input) + } + } + + override val deserializationAliases: Set> = Collections.singleton(Currency::class.java) + + override val schemaForDocumentation: Schema = Schema(emptyList()) + + override fun readObject(obj: Any, schemas: SerializationSchemas, input: DeserializationInput, context: SerializationContext): Any { + return creator.apply(obj)!! + } + + override fun writeDescribedObject(obj: Any, data: Data, type: Type, output: SerializationOutput, context: SerializationContext) { + abortReadOnly() + } +} diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDecimal128Serializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDecimal128Serializer.kt new file mode 100644 index 0000000000..7f5da69f5e --- /dev/null +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDecimal128Serializer.kt @@ -0,0 +1,37 @@ +package net.corda.djvm.serialization.serializers + +import net.corda.core.serialization.SerializationContext +import net.corda.djvm.rewiring.SandboxClassLoader +import net.corda.djvm.serialization.deserializers.Decimal128Deserializer +import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.serialization.internal.amqp.* +import org.apache.qpid.proton.amqp.Decimal128 +import org.apache.qpid.proton.codec.Data +import java.lang.reflect.Type +import java.util.function.BiFunction +import java.util.function.Function + +class SandboxDecimal128Serializer( + classLoader: SandboxClassLoader, + executor: BiFunction +) : CustomSerializer.Is(classLoader.loadClassForSandbox(Decimal128::class.java)) { + private val transformer: Function + + init { + val transformTask = classLoader.loadClassForSandbox(Decimal128Deserializer::class.java).newInstance() + transformer = Function { inputs -> + executor.apply(transformTask, inputs) + } + } + + override val schemaForDocumentation: Schema = Schema(emptyList()) + + override fun readObject(obj: Any, schemas: SerializationSchemas, input: DeserializationInput, context: SerializationContext): Any { + val decimal128 = obj as Decimal128 + return transformer.apply(longArrayOf(decimal128.mostSignificantBits, decimal128.leastSignificantBits))!! + } + + override fun writeDescribedObject(obj: Any, data: Data, type: Type, output: SerializationOutput, context: SerializationContext) { + abortReadOnly() + } +} diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDecimal32Serializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDecimal32Serializer.kt new file mode 100644 index 0000000000..d0d8016683 --- /dev/null +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDecimal32Serializer.kt @@ -0,0 +1,36 @@ +package net.corda.djvm.serialization.serializers + +import net.corda.core.serialization.SerializationContext +import net.corda.djvm.rewiring.SandboxClassLoader +import net.corda.djvm.serialization.deserializers.Decimal32Deserializer +import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.serialization.internal.amqp.* +import org.apache.qpid.proton.amqp.Decimal32 +import org.apache.qpid.proton.codec.Data +import java.lang.reflect.Type +import java.util.function.BiFunction +import java.util.function.Function + +class SandboxDecimal32Serializer( + classLoader: SandboxClassLoader, + executor: BiFunction +) : CustomSerializer.Is(classLoader.loadClassForSandbox(Decimal32::class.java)) { + private val transformer: Function + + init { + val transformTask = classLoader.loadClassForSandbox(Decimal32Deserializer::class.java).newInstance() + transformer = Function { inputs -> + executor.apply(transformTask, inputs) + } + } + + override val schemaForDocumentation: Schema = Schema(emptyList()) + + override fun readObject(obj: Any, schemas: SerializationSchemas, input: DeserializationInput, context: SerializationContext): Any { + return transformer.apply(intArrayOf((obj as Decimal32).bits))!! + } + + override fun writeDescribedObject(obj: Any, data: Data, type: Type, output: SerializationOutput, context: SerializationContext) { + abortReadOnly() + } +} diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDecimal64Serializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDecimal64Serializer.kt new file mode 100644 index 0000000000..c77820712d --- /dev/null +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDecimal64Serializer.kt @@ -0,0 +1,36 @@ +package net.corda.djvm.serialization.serializers + +import net.corda.core.serialization.SerializationContext +import net.corda.djvm.rewiring.SandboxClassLoader +import net.corda.djvm.serialization.deserializers.Decimal64Deserializer +import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.serialization.internal.amqp.* +import org.apache.qpid.proton.amqp.Decimal64 +import org.apache.qpid.proton.codec.Data +import java.lang.reflect.Type +import java.util.function.BiFunction +import java.util.function.Function + +class SandboxDecimal64Serializer( + classLoader: SandboxClassLoader, + executor: BiFunction +) : CustomSerializer.Is(classLoader.loadClassForSandbox(Decimal64::class.java)) { + private val transformer: Function + + init { + val transformTask = classLoader.loadClassForSandbox(Decimal64Deserializer::class.java).newInstance() + transformer = Function { inputs -> + executor.apply(transformTask, inputs) + } + } + + override val schemaForDocumentation: Schema = Schema(emptyList()) + + override fun readObject(obj: Any, schemas: SerializationSchemas, input: DeserializationInput, context: SerializationContext): Any { + return transformer.apply(longArrayOf((obj as Decimal64).bits))!! + } + + override fun writeDescribedObject(obj: Any, data: Data, type: Type, output: SerializationOutput, context: SerializationContext) { + abortReadOnly() + } +} diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDurationSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDurationSerializer.kt new file mode 100644 index 0000000000..48586ce4df --- /dev/null +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDurationSerializer.kt @@ -0,0 +1,31 @@ +package net.corda.djvm.serialization.serializers + +import net.corda.djvm.rewiring.SandboxClassLoader +import net.corda.djvm.serialization.deserializers.DurationDeserializer +import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.serialization.internal.amqp.CustomSerializer +import net.corda.serialization.internal.amqp.SerializerFactory +import net.corda.serialization.internal.amqp.custom.DurationSerializer.DurationProxy +import java.time.Duration +import java.util.Collections.singleton +import java.util.function.BiFunction + +class SandboxDurationSerializer( + classLoader: SandboxClassLoader, + private val executor: BiFunction, + factory: SerializerFactory +) : CustomSerializer.Proxy( + clazz = classLoader.loadClassForSandbox(Duration::class.java), + proxyClass = classLoader.loadClassForSandbox(DurationProxy::class.java), + factory = factory +) { + private val task = classLoader.loadClassForSandbox(DurationDeserializer::class.java).newInstance() + + override val deserializationAliases: Set> = singleton(Duration::class.java) + + override fun toProxy(obj: Any): Any = abortReadOnly() + + override fun fromProxy(proxy: Any): Any { + return executor.apply(task, proxy)!! + } +} diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxEnumSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxEnumSerializer.kt new file mode 100644 index 0000000000..fedb92450a --- /dev/null +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxEnumSerializer.kt @@ -0,0 +1,95 @@ +package net.corda.djvm.serialization.serializers + +import net.corda.core.serialization.SerializationContext +import net.corda.djvm.rewiring.SandboxClassLoader +import net.corda.djvm.serialization.deserializers.DescribeEnum +import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.serialization.internal.amqp.* +import net.corda.serialization.internal.model.EnumTransforms +import net.corda.serialization.internal.model.LocalTypeInformation +import net.corda.serialization.internal.model.TypeIdentifier +import org.apache.qpid.proton.amqp.Symbol +import org.apache.qpid.proton.codec.Data +import java.lang.reflect.Type +import java.util.function.BiFunction +import java.util.function.Function + +class SandboxEnumSerializer( + classLoader: SandboxClassLoader, + executor: BiFunction, + private val localFactory: LocalSerializerFactory +) : CustomSerializer.Implements(clazz = classLoader.loadClassForSandbox(Enum::class.java)) { + private val describer: Function, Array> + + init { + val describeTask = classLoader.loadClassForSandbox(DescribeEnum::class.java).newInstance() + describer = Function { inputs -> + @Suppress("unchecked_cast") + executor.apply(describeTask, inputs) as Array + } + } + + override val schemaForDocumentation: Schema = Schema(emptyList()) + + override fun specialiseFor(declaredType: Type): AMQPSerializer? { + if (declaredType !is Class<*>) { + return null + } + val members = describer.apply(declaredType) + return ConcreteEnumSerializer(declaredType, members, localFactory) + } + + override fun readObject(obj: Any, schemas: SerializationSchemas, input: DeserializationInput, context: SerializationContext): Any { + throw UnsupportedOperationException("Factory only") + } + + override fun writeDescribedObject(obj: Any, data: Data, type: Type, output: SerializationOutput, context: SerializationContext) { + throw UnsupportedOperationException("Factory Only") + } +} + +private class ConcreteEnumSerializer( + declaredType: Class<*>, + private val members: Array, + factory: LocalSerializerFactory +) : AMQPSerializer { + override val type: Class<*> = declaredType + + override val typeDescriptor: Symbol by lazy { + factory.createDescriptor( + /* + * Partially populated, providing just the information + * required by the fingerprinter. + */ + LocalTypeInformation.AnEnum( + declaredType, + TypeIdentifier.forGenericType(declaredType), + members.map { it.toString() }, + emptyList(), + EnumTransforms.empty + ) + ) + } + + override fun readObject(obj: Any, schemas: SerializationSchemas, input: DeserializationInput, context: SerializationContext): Any { + val enumName = (obj as List<*>)[0] as String + val enumOrd = obj[1] as Int + val fromOrd = members[enumOrd] + + if (enumName != fromOrd.toString()) { + throw AMQPNotSerializableException( + type, + "Deserializing obj as enum $type with value $enumName.$enumOrd but ordinality has changed" + ) + } + return fromOrd + } + + override fun writeClassInfo(output: SerializationOutput) { + abortReadOnly() + } + + override fun writeObject(obj: Any, data: Data, type: Type, output: SerializationOutput, context: SerializationContext, debugIndent: Int) { + abortReadOnly() + } +} \ No newline at end of file diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxEnumSetSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxEnumSetSerializer.kt new file mode 100644 index 0000000000..fe839f2b5c --- /dev/null +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxEnumSetSerializer.kt @@ -0,0 +1,35 @@ +package net.corda.djvm.serialization.serializers + +import net.corda.djvm.rewiring.SandboxClassLoader +import net.corda.djvm.serialization.deserializers.EnumSetDeserializer +import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.serialization.internal.amqp.CustomSerializer +import net.corda.serialization.internal.amqp.SerializerFactory +import net.corda.serialization.internal.amqp.custom.EnumSetSerializer.EnumSetProxy +import java.util.* +import java.util.Collections.singleton +import java.util.function.BiFunction + +class SandboxEnumSetSerializer( + classLoader: SandboxClassLoader, + private val executor: BiFunction, + factory: SerializerFactory +) : CustomSerializer.Proxy( + clazz = classLoader.loadClassForSandbox(EnumSet::class.java), + proxyClass = classLoader.loadClassForSandbox(EnumSetProxy::class.java), + factory = factory +) { + private val task = classLoader.loadClassForSandbox(EnumSetDeserializer::class.java).newInstance() + + override val additionalSerializers: Set> = singleton( + SandboxClassSerializer(classLoader, executor, factory) + ) + + override val deserializationAliases: Set> = singleton(EnumSet::class.java) + + override fun toProxy(obj: Any): Any = abortReadOnly() + + override fun fromProxy(proxy: Any): Any { + return executor.apply(task, proxy)!! + } +} diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxInstantSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxInstantSerializer.kt new file mode 100644 index 0000000000..ea867b146a --- /dev/null +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxInstantSerializer.kt @@ -0,0 +1,31 @@ +package net.corda.djvm.serialization.serializers + +import net.corda.djvm.rewiring.SandboxClassLoader +import net.corda.djvm.serialization.deserializers.InstantDeserializer +import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.serialization.internal.amqp.CustomSerializer +import net.corda.serialization.internal.amqp.SerializerFactory +import net.corda.serialization.internal.amqp.custom.InstantSerializer.InstantProxy +import java.time.Instant +import java.util.Collections.singleton +import java.util.function.BiFunction + +class SandboxInstantSerializer( + classLoader: SandboxClassLoader, + private val executor: BiFunction, + factory: SerializerFactory +) : CustomSerializer.Proxy( + clazz = classLoader.loadClassForSandbox(Instant::class.java), + proxyClass = classLoader.loadClassForSandbox(InstantProxy::class.java), + factory = factory +) { + private val task = classLoader.loadClassForSandbox(InstantDeserializer::class.java).newInstance() + + override val deserializationAliases: Set> = singleton(Instant::class.java) + + override fun toProxy(obj: Any): Any = abortReadOnly() + + override fun fromProxy(proxy: Any): Any { + return executor.apply(task, proxy)!! + } +} diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxLocalDateSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxLocalDateSerializer.kt new file mode 100644 index 0000000000..4a8cbb256b --- /dev/null +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxLocalDateSerializer.kt @@ -0,0 +1,31 @@ +package net.corda.djvm.serialization.serializers + +import net.corda.djvm.rewiring.SandboxClassLoader +import net.corda.djvm.serialization.deserializers.LocalDateDeserializer +import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.serialization.internal.amqp.CustomSerializer +import net.corda.serialization.internal.amqp.SerializerFactory +import net.corda.serialization.internal.amqp.custom.LocalDateSerializer.LocalDateProxy +import java.time.LocalDate +import java.util.Collections.singleton +import java.util.function.BiFunction + +class SandboxLocalDateSerializer( + classLoader: SandboxClassLoader, + private val executor: BiFunction, + factory: SerializerFactory +) : CustomSerializer.Proxy( + clazz = classLoader.loadClassForSandbox(LocalDate::class.java), + proxyClass = classLoader.loadClassForSandbox(LocalDateProxy::class.java), + factory = factory +) { + private val task = classLoader.loadClassForSandbox(LocalDateDeserializer::class.java).newInstance() + + override val deserializationAliases: Set> = singleton(LocalDate::class.java) + + override fun toProxy(obj: Any): Any = abortReadOnly() + + override fun fromProxy(proxy: Any): Any { + return executor.apply(task, proxy)!! + } +} diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxLocalDateTimeSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxLocalDateTimeSerializer.kt new file mode 100644 index 0000000000..d027a5b61c --- /dev/null +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxLocalDateTimeSerializer.kt @@ -0,0 +1,31 @@ +package net.corda.djvm.serialization.serializers + +import net.corda.djvm.rewiring.SandboxClassLoader +import net.corda.djvm.serialization.deserializers.LocalDateTimeDeserializer +import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.serialization.internal.amqp.CustomSerializer +import net.corda.serialization.internal.amqp.SerializerFactory +import net.corda.serialization.internal.amqp.custom.LocalDateTimeSerializer.LocalDateTimeProxy +import java.time.LocalDateTime +import java.util.Collections.singleton +import java.util.function.BiFunction + +class SandboxLocalDateTimeSerializer( + classLoader: SandboxClassLoader, + private val executor: BiFunction, + factory: SerializerFactory +) : CustomSerializer.Proxy( + clazz = classLoader.loadClassForSandbox(LocalDateTime::class.java), + proxyClass = classLoader.loadClassForSandbox(LocalDateTimeProxy::class.java), + factory = factory +) { + private val task = classLoader.loadClassForSandbox(LocalDateTimeDeserializer::class.java).newInstance() + + override val deserializationAliases: Set> = singleton(LocalDateTime::class.java) + + override fun toProxy(obj: Any): Any = abortReadOnly() + + override fun fromProxy(proxy: Any): Any { + return executor.apply(task, proxy)!! + } +} diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxLocalTimeSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxLocalTimeSerializer.kt new file mode 100644 index 0000000000..87dfa15e26 --- /dev/null +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxLocalTimeSerializer.kt @@ -0,0 +1,31 @@ +package net.corda.djvm.serialization.serializers + +import net.corda.djvm.rewiring.SandboxClassLoader +import net.corda.djvm.serialization.deserializers.LocalTimeDeserializer +import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.serialization.internal.amqp.CustomSerializer +import net.corda.serialization.internal.amqp.SerializerFactory +import net.corda.serialization.internal.amqp.custom.LocalTimeSerializer.LocalTimeProxy +import java.time.LocalTime +import java.util.Collections.singleton +import java.util.function.BiFunction + +class SandboxLocalTimeSerializer( + classLoader: SandboxClassLoader, + private val executor: BiFunction, + factory: SerializerFactory +) : CustomSerializer.Proxy( + clazz = classLoader.loadClassForSandbox(LocalTime::class.java), + proxyClass = classLoader.loadClassForSandbox(LocalTimeProxy::class.java), + factory = factory +) { + private val task = classLoader.loadClassForSandbox(LocalTimeDeserializer::class.java).newInstance() + + override val deserializationAliases: Set> = singleton(LocalTime::class.java) + + override fun toProxy(obj: Any): Any = abortReadOnly() + + override fun fromProxy(proxy: Any): Any { + return executor.apply(task, proxy)!! + } +} diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxMapSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxMapSerializer.kt new file mode 100644 index 0000000000..2489b53742 --- /dev/null +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxMapSerializer.kt @@ -0,0 +1,114 @@ +package net.corda.djvm.serialization.serializers + +import net.corda.core.serialization.SerializationContext +import net.corda.djvm.rewiring.SandboxClassLoader +import net.corda.djvm.serialization.deserializers.CreateMap +import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.serialization.internal.amqp.* +import net.corda.serialization.internal.model.LocalTypeInformation +import net.corda.serialization.internal.model.TypeIdentifier +import org.apache.qpid.proton.amqp.Symbol +import org.apache.qpid.proton.codec.Data +import java.lang.reflect.ParameterizedType +import java.lang.reflect.Type +import java.util.* +import java.util.function.BiFunction +import java.util.function.Function + +class SandboxMapSerializer( + classLoader: SandboxClassLoader, + executor: BiFunction, + private val localFactory: LocalSerializerFactory +) : CustomSerializer.Implements(clazz = classLoader.loadClassForSandbox(Map::class.java)) { + private val creator: Function, out Any?> + + init { + val createTask = classLoader.loadClassForSandbox(CreateMap::class.java).newInstance() + creator = Function { inputs -> + executor.apply(createTask, inputs) + } + } + + // The order matters here - the first match should be the most specific one. + // Kotlin preserves the ordering for us by associating into a LinkedHashMap. + private val supportedTypes: Map, Class>> = listOf( + TreeMap::class.java, + LinkedHashMap::class.java, + NavigableMap::class.java, + SortedMap::class.java, + EnumMap::class.java, + Map::class.java + ).associateBy { + classLoader.loadClassForSandbox(it) + } + + private fun getBestMatchFor(type: Class): Map.Entry, Class>> + = supportedTypes.entries.first { it.key.isAssignableFrom(type) } + + override val schemaForDocumentation: Schema = Schema(emptyList()) + + override fun specialiseFor(declaredType: Type): AMQPSerializer? { + if (declaredType !is ParameterizedType) { + return null + } + + @Suppress("unchecked_cast") + val rawType = declaredType.rawType as Class + return ConcreteMapSerializer(declaredType, getBestMatchFor(rawType), creator, localFactory) + } + + override fun readObject(obj: Any, schemas: SerializationSchemas, input: DeserializationInput, context: SerializationContext): Any { + throw UnsupportedOperationException("Factory only") + } + + override fun writeDescribedObject(obj: Any, data: Data, type: Type, output: SerializationOutput, context: SerializationContext) { + throw UnsupportedOperationException("Factory Only") + } +} + +private class ConcreteMapSerializer( + declaredType: ParameterizedType, + private val matchingType: Map.Entry, Class>>, + private val creator: Function, out Any?>, + factory: LocalSerializerFactory +) : AMQPSerializer { + override val type: ParameterizedType = declaredType + + override val typeDescriptor: Symbol by lazy { + factory.createDescriptor( + LocalTypeInformation.AMap( + observedType = declaredType.rawType, + typeIdentifier = TypeIdentifier.forGenericType(declaredType), + keyType =factory.getTypeInformation(declaredType.actualTypeArguments[0]), + valueType = factory.getTypeInformation(declaredType.actualTypeArguments[1]) + ) + ) + } + + override fun readObject( + obj: Any, + schemas: SerializationSchemas, + input: DeserializationInput, + context: SerializationContext + ): Any { + val inboundKeyType = type.actualTypeArguments[0] + val inboundValueType = type.actualTypeArguments[1] + return ifThrowsAppend({ type.typeName }) { + val entries = (obj as Map<*, *>).map { + arrayOf( + input.readObjectOrNull(redescribe(it.key, inboundKeyType), schemas, inboundKeyType, context), + input.readObjectOrNull(redescribe(it.value, inboundValueType), schemas, inboundValueType, context) + ) + }.toTypedArray() + creator.apply(arrayOf(matchingType.key, entries))!! + } + } + + override fun writeClassInfo(output: SerializationOutput) { + abortReadOnly() + } + + override fun writeObject(obj: Any, data: Data, type: Type, output: SerializationOutput, context: SerializationContext, debugIndent: Int) { + abortReadOnly() + } +} diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxMonthDaySerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxMonthDaySerializer.kt new file mode 100644 index 0000000000..cd489228b2 --- /dev/null +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxMonthDaySerializer.kt @@ -0,0 +1,31 @@ +package net.corda.djvm.serialization.serializers + +import net.corda.djvm.rewiring.SandboxClassLoader +import net.corda.djvm.serialization.deserializers.MonthDayDeserializer +import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.serialization.internal.amqp.CustomSerializer +import net.corda.serialization.internal.amqp.SerializerFactory +import net.corda.serialization.internal.amqp.custom.MonthDaySerializer.MonthDayProxy +import java.time.MonthDay +import java.util.Collections.singleton +import java.util.function.BiFunction + +class SandboxMonthDaySerializer( + classLoader: SandboxClassLoader, + private val executor: BiFunction, + factory: SerializerFactory +) : CustomSerializer.Proxy( + clazz = classLoader.loadClassForSandbox(MonthDay::class.java), + proxyClass = classLoader.loadClassForSandbox(MonthDayProxy::class.java), + factory = factory +) { + private val task = classLoader.loadClassForSandbox(MonthDayDeserializer::class.java).newInstance() + + override val deserializationAliases: Set> = singleton(MonthDay::class.java) + + override fun toProxy(obj: Any): Any = abortReadOnly() + + override fun fromProxy(proxy: Any): Any { + return executor.apply(task, proxy)!! + } +} diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOffsetDateTimeSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOffsetDateTimeSerializer.kt new file mode 100644 index 0000000000..54091ab2be --- /dev/null +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOffsetDateTimeSerializer.kt @@ -0,0 +1,31 @@ +package net.corda.djvm.serialization.serializers + +import net.corda.djvm.rewiring.SandboxClassLoader +import net.corda.djvm.serialization.deserializers.OffsetDateTimeDeserializer +import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.serialization.internal.amqp.CustomSerializer +import net.corda.serialization.internal.amqp.SerializerFactory +import net.corda.serialization.internal.amqp.custom.OffsetDateTimeSerializer.OffsetDateTimeProxy +import java.time.OffsetDateTime +import java.util.Collections.singleton +import java.util.function.BiFunction + +class SandboxOffsetDateTimeSerializer( + classLoader: SandboxClassLoader, + private val executor: BiFunction, + factory: SerializerFactory +) : CustomSerializer.Proxy( + clazz = classLoader.loadClassForSandbox(OffsetDateTime::class.java), + proxyClass = classLoader.loadClassForSandbox(OffsetDateTimeProxy::class.java), + factory = factory +) { + private val task = classLoader.loadClassForSandbox(OffsetDateTimeDeserializer::class.java).newInstance() + + override val deserializationAliases: Set> = singleton(OffsetDateTime::class.java) + + override fun toProxy(obj: Any): Any = abortReadOnly() + + override fun fromProxy(proxy: Any): Any { + return executor.apply(task, proxy)!! + } +} diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOffsetTimeSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOffsetTimeSerializer.kt new file mode 100644 index 0000000000..284465a4de --- /dev/null +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOffsetTimeSerializer.kt @@ -0,0 +1,31 @@ +package net.corda.djvm.serialization.serializers + +import net.corda.djvm.rewiring.SandboxClassLoader +import net.corda.djvm.serialization.deserializers.OffsetTimeDeserializer +import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.serialization.internal.amqp.CustomSerializer +import net.corda.serialization.internal.amqp.SerializerFactory +import net.corda.serialization.internal.amqp.custom.OffsetTimeSerializer.OffsetTimeProxy +import java.time.OffsetTime +import java.util.Collections.singleton +import java.util.function.BiFunction + +class SandboxOffsetTimeSerializer( + classLoader: SandboxClassLoader, + private val executor: BiFunction, + factory: SerializerFactory +) : CustomSerializer.Proxy( + clazz = classLoader.loadClassForSandbox(OffsetTime::class.java), + proxyClass = classLoader.loadClassForSandbox(OffsetTimeProxy::class.java), + factory = factory +) { + private val task = classLoader.loadClassForSandbox(OffsetTimeDeserializer::class.java).newInstance() + + override val deserializationAliases: Set> = singleton(OffsetTime::class.java) + + override fun toProxy(obj: Any): Any = abortReadOnly() + + override fun fromProxy(proxy: Any): Any { + return executor.apply(task, proxy)!! + } +} diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOptionalSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOptionalSerializer.kt new file mode 100644 index 0000000000..733ceabc93 --- /dev/null +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOptionalSerializer.kt @@ -0,0 +1,31 @@ +package net.corda.djvm.serialization.serializers + +import net.corda.djvm.rewiring.SandboxClassLoader +import net.corda.djvm.serialization.deserializers.OptionalDeserializer +import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.serialization.internal.amqp.CustomSerializer +import net.corda.serialization.internal.amqp.SerializerFactory +import net.corda.serialization.internal.amqp.custom.OptionalSerializer.OptionalProxy +import java.util.* +import java.util.Collections.singleton +import java.util.function.BiFunction + +class SandboxOptionalSerializer( + classLoader: SandboxClassLoader, + private val executor: BiFunction, + factory: SerializerFactory +) : CustomSerializer.Proxy( + clazz = classLoader.loadClassForSandbox(Optional::class.java), + proxyClass = classLoader.loadClassForSandbox(OptionalProxy::class.java), + factory = factory +) { + private val task = classLoader.loadClassForSandbox(OptionalDeserializer::class.java).newInstance() + + override val deserializationAliases: Set> = singleton(Optional::class.java) + + override fun toProxy(obj: Any): Any = abortReadOnly() + + override fun fromProxy(proxy: Any): Any { + return executor.apply(task, proxy)!! + } +} diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxPeriodSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxPeriodSerializer.kt new file mode 100644 index 0000000000..31ad835f1c --- /dev/null +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxPeriodSerializer.kt @@ -0,0 +1,31 @@ +package net.corda.djvm.serialization.serializers + +import net.corda.djvm.rewiring.SandboxClassLoader +import net.corda.djvm.serialization.deserializers.PeriodDeserializer +import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.serialization.internal.amqp.CustomSerializer +import net.corda.serialization.internal.amqp.SerializerFactory +import net.corda.serialization.internal.amqp.custom.PeriodSerializer.PeriodProxy +import java.time.Period +import java.util.Collections.singleton +import java.util.function.BiFunction + +class SandboxPeriodSerializer( + classLoader: SandboxClassLoader, + private val executor: BiFunction, + factory: SerializerFactory +) : CustomSerializer.Proxy( + clazz = classLoader.loadClassForSandbox(Period::class.java), + proxyClass = classLoader.loadClassForSandbox(PeriodProxy::class.java), + factory = factory +) { + private val task = classLoader.loadClassForSandbox(PeriodDeserializer::class.java).newInstance() + + override val deserializationAliases: Set> = singleton(Period::class.java) + + override fun toProxy(obj: Any): Any = abortReadOnly() + + override fun fromProxy(proxy: Any): Any { + return executor.apply(task, proxy)!! + } +} diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxPrimitiveSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxPrimitiveSerializer.kt new file mode 100644 index 0000000000..b5eeb43927 --- /dev/null +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxPrimitiveSerializer.kt @@ -0,0 +1,26 @@ +package net.corda.djvm.serialization.serializers + +import net.corda.core.serialization.SerializationContext +import net.corda.djvm.rewiring.SandboxClassLoader +import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.serialization.internal.amqp.* +import org.apache.qpid.proton.codec.Data +import java.lang.reflect.Type +import java.util.function.Function + +class SandboxPrimitiveSerializer( + clazz: Class<*>, + classLoader: SandboxClassLoader, + private val basicInput: Function +) : CustomSerializer.Is(classLoader.loadClassForSandbox(clazz)) { + + override val schemaForDocumentation: Schema = Schema(emptyList()) + + override fun readObject(obj: Any, schemas: SerializationSchemas, input: DeserializationInput, context: SerializationContext): Any { + return basicInput.apply(obj)!! + } + + override fun writeDescribedObject(obj: Any, data: Data, type: Type, output: SerializationOutput, context: SerializationContext) { + abortReadOnly() + } +} diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxPublicKeySerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxPublicKeySerializer.kt new file mode 100644 index 0000000000..4bbca81690 --- /dev/null +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxPublicKeySerializer.kt @@ -0,0 +1,40 @@ +package net.corda.djvm.serialization.serializers + +import net.corda.core.serialization.SerializationContext +import net.corda.djvm.rewiring.SandboxClassLoader +import net.corda.djvm.serialization.deserializers.PublicKeyDecoder +import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.serialization.internal.amqp.* +import org.apache.qpid.proton.codec.Data +import java.lang.reflect.Type +import java.security.PublicKey +import java.util.Collections.singleton +import java.util.function.BiFunction +import java.util.function.Function + +class SandboxPublicKeySerializer( + classLoader: SandboxClassLoader, + executor: BiFunction +) : CustomSerializer.Implements(classLoader.loadClassForSandbox(PublicKey::class.java)) { + private val decoder: Function + + init { + val decodeTask = classLoader.loadClassForSandbox(PublicKeyDecoder::class.java).newInstance() + decoder = Function { inputs -> + executor.apply(decodeTask, inputs) + } + } + + override val schemaForDocumentation: Schema = Schema(emptyList()) + + override val deserializationAliases: Set> = singleton(PublicKey::class.java) + + override fun readObject(obj: Any, schemas: SerializationSchemas, input: DeserializationInput, context: SerializationContext): Any { + val bits = input.readObject(obj, schemas, ByteArray::class.java, context) as ByteArray + return decoder.apply(bits)!! + } + + override fun writeDescribedObject(obj: Any, data: Data, type: Type, output: SerializationOutput, context: SerializationContext) { + abortReadOnly() + } +} diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxSymbolSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxSymbolSerializer.kt new file mode 100644 index 0000000000..95ce4a7694 --- /dev/null +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxSymbolSerializer.kt @@ -0,0 +1,38 @@ +package net.corda.djvm.serialization.serializers + +import net.corda.core.serialization.SerializationContext +import net.corda.djvm.rewiring.SandboxClassLoader +import net.corda.djvm.serialization.deserializers.SymbolDeserializer +import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.serialization.internal.amqp.* +import org.apache.qpid.proton.amqp.Symbol +import org.apache.qpid.proton.codec.Data +import java.lang.reflect.Type +import java.util.function.BiFunction +import java.util.function.Function + +class SandboxSymbolSerializer( + classLoader: SandboxClassLoader, + executor: BiFunction, + basicInput: Function +) : CustomSerializer.Is(classLoader.loadClassForSandbox(Symbol::class.java)) { + private val transformer: Function + + init { + val transformTask = classLoader.loadClassForSandbox(SymbolDeserializer::class.java).newInstance() + @Suppress("unchecked_cast") + transformer = basicInput.andThen { input -> + executor.apply(transformTask, input) + } as Function + } + + override val schemaForDocumentation: Schema = Schema(emptyList()) + + override fun readObject(obj: Any, schemas: SerializationSchemas, input: DeserializationInput, context: SerializationContext): Any { + return transformer.apply((obj as Symbol).toString())!! + } + + override fun writeDescribedObject(obj: Any, data: Data, type: Type, output: SerializationOutput, context: SerializationContext) { + abortReadOnly() + } +} diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxToStringSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxToStringSerializer.kt new file mode 100644 index 0000000000..765a406e1a --- /dev/null +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxToStringSerializer.kt @@ -0,0 +1,44 @@ +package net.corda.djvm.serialization.serializers + +import net.corda.core.serialization.SerializationContext +import net.corda.djvm.rewiring.SandboxClassLoader +import net.corda.djvm.serialization.deserializers.CreateFromString +import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.serialization.internal.amqp.* +import org.apache.qpid.proton.codec.Data +import java.lang.reflect.Constructor +import java.lang.reflect.Type +import java.util.Collections.singleton +import java.util.function.BiFunction +import java.util.function.Function + +class SandboxToStringSerializer( + unsafeClass: Class<*>, + classLoader: SandboxClassLoader, + executor: BiFunction, + basicInput: Function +) : CustomSerializer.Is(classLoader.loadClassForSandbox(unsafeClass)) { + private val creator: Function + + init { + val stringClass = classLoader.loadClass("sandbox.java.lang.String") + val createTask = classLoader.loadClassForSandbox(CreateFromString::class.java) + .getConstructor(Constructor::class.java) + .newInstance(clazz.getConstructor(stringClass)) + creator = basicInput.andThen { input -> + executor.apply(createTask, input) + } + } + + override val deserializationAliases: Set> = singleton(unsafeClass) + + override val schemaForDocumentation: Schema = Schema(emptyList()) + + override fun readObject(obj: Any, schemas: SerializationSchemas, input: DeserializationInput, context: SerializationContext): Any { + return creator.apply(obj)!! + } + + override fun writeDescribedObject(obj: Any, data: Data, type: Type, output: SerializationOutput, context: SerializationContext) { + abortReadOnly() + } +} diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedByteSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedByteSerializer.kt new file mode 100644 index 0000000000..30a208471a --- /dev/null +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedByteSerializer.kt @@ -0,0 +1,36 @@ +package net.corda.djvm.serialization.serializers + +import net.corda.core.serialization.SerializationContext +import net.corda.djvm.rewiring.SandboxClassLoader +import net.corda.djvm.serialization.deserializers.UnsignedByteDeserializer +import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.serialization.internal.amqp.* +import org.apache.qpid.proton.amqp.UnsignedByte +import org.apache.qpid.proton.codec.Data +import java.lang.reflect.Type +import java.util.function.BiFunction +import java.util.function.Function + +class SandboxUnsignedByteSerializer( + classLoader: SandboxClassLoader, + executor: BiFunction +) : CustomSerializer.Is(classLoader.loadClassForSandbox(UnsignedByte::class.java)) { + private val transformer: Function + + init { + val transformTask = classLoader.loadClassForSandbox(UnsignedByteDeserializer::class.java).newInstance() + transformer = Function { inputs -> + executor.apply(transformTask, inputs) + } + } + + override val schemaForDocumentation: Schema = Schema(emptyList()) + + override fun readObject(obj: Any, schemas: SerializationSchemas, input: DeserializationInput, context: SerializationContext): Any { + return transformer.apply(byteArrayOf((obj as UnsignedByte).toByte()))!! + } + + override fun writeDescribedObject(obj: Any, data: Data, type: Type, output: SerializationOutput, context: SerializationContext) { + abortReadOnly() + } +} diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedIntegerSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedIntegerSerializer.kt new file mode 100644 index 0000000000..15b7ee6bcb --- /dev/null +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedIntegerSerializer.kt @@ -0,0 +1,36 @@ +package net.corda.djvm.serialization.serializers + +import net.corda.core.serialization.SerializationContext +import net.corda.djvm.rewiring.SandboxClassLoader +import net.corda.djvm.serialization.deserializers.UnsignedIntegerDeserializer +import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.serialization.internal.amqp.* +import org.apache.qpid.proton.amqp.UnsignedInteger +import org.apache.qpid.proton.codec.Data +import java.lang.reflect.Type +import java.util.function.BiFunction +import java.util.function.Function + +class SandboxUnsignedIntegerSerializer( + classLoader: SandboxClassLoader, + executor: BiFunction +) : CustomSerializer.Is(classLoader.loadClassForSandbox(UnsignedInteger::class.java)) { + private val transformer: Function + + init { + val transformTask = classLoader.loadClassForSandbox(UnsignedIntegerDeserializer::class.java).newInstance() + transformer = Function { inputs -> + executor.apply(transformTask, inputs) + } + } + + override val schemaForDocumentation: Schema = Schema(emptyList()) + + override fun readObject(obj: Any, schemas: SerializationSchemas, input: DeserializationInput, context: SerializationContext): Any { + return transformer.apply(intArrayOf((obj as UnsignedInteger).toInt()))!! + } + + override fun writeDescribedObject(obj: Any, data: Data, type: Type, output: SerializationOutput, context: SerializationContext) { + abortReadOnly() + } +} diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedLongSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedLongSerializer.kt new file mode 100644 index 0000000000..d63d7469da --- /dev/null +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedLongSerializer.kt @@ -0,0 +1,37 @@ +package net.corda.djvm.serialization.serializers + +import net.corda.core.serialization.SerializationContext +import net.corda.djvm.rewiring.SandboxClassLoader +import net.corda.djvm.serialization.deserializers.UnsignedLongDeserializer +import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.serialization.internal.amqp.* +import org.apache.qpid.proton.amqp.UnsignedLong +import org.apache.qpid.proton.codec.Data +import java.lang.reflect.Type +import java.util.Collections.singleton +import java.util.function.BiFunction +import java.util.function.Function + +class SandboxUnsignedLongSerializer( + classLoader: SandboxClassLoader, + executor: BiFunction +) : CustomSerializer.Is(classLoader.loadClassForSandbox(UnsignedLong::class.java)) { + private val transformer: Function + + init { + val transformTask = classLoader.loadClassForSandbox(UnsignedLongDeserializer::class.java).newInstance() + transformer = Function { inputs -> + executor.apply(transformTask, inputs) + } + } + + override val schemaForDocumentation: Schema = Schema(emptyList()) + + override fun readObject(obj: Any, schemas: SerializationSchemas, input: DeserializationInput, context: SerializationContext): Any { + return transformer.apply(longArrayOf((obj as UnsignedLong).toLong()))!! + } + + override fun writeDescribedObject(obj: Any, data: Data, type: Type, output: SerializationOutput, context: SerializationContext) { + abortReadOnly() + } +} \ No newline at end of file diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedShortSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedShortSerializer.kt new file mode 100644 index 0000000000..6eaa91b9ef --- /dev/null +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedShortSerializer.kt @@ -0,0 +1,36 @@ +package net.corda.djvm.serialization.serializers + +import net.corda.core.serialization.SerializationContext +import net.corda.djvm.rewiring.SandboxClassLoader +import net.corda.djvm.serialization.deserializers.UnsignedShortDeserializer +import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.serialization.internal.amqp.* +import org.apache.qpid.proton.amqp.UnsignedShort +import org.apache.qpid.proton.codec.Data +import java.lang.reflect.Type +import java.util.function.BiFunction +import java.util.function.Function + +class SandboxUnsignedShortSerializer( + classLoader: SandboxClassLoader, + executor: BiFunction +) : CustomSerializer.Is(classLoader.loadClassForSandbox(UnsignedShort::class.java)) { + private val transformer: Function + + init { + val transformTask = classLoader.loadClassForSandbox(UnsignedShortDeserializer::class.java).newInstance() + transformer = Function { inputs -> + executor.apply(transformTask, inputs) + } + } + + override val schemaForDocumentation: Schema = Schema(emptyList()) + + override fun readObject(obj: Any, schemas: SerializationSchemas, input: DeserializationInput, context: SerializationContext): Any { + return transformer.apply(shortArrayOf((obj as UnsignedShort).toShort()))!! + } + + override fun writeDescribedObject(obj: Any, data: Data, type: Type, output: SerializationOutput, context: SerializationContext) { + abortReadOnly() + } +} diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxX509CRLSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxX509CRLSerializer.kt new file mode 100644 index 0000000000..a9f4ae85a2 --- /dev/null +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxX509CRLSerializer.kt @@ -0,0 +1,40 @@ +package net.corda.djvm.serialization.serializers + +import net.corda.core.serialization.SerializationContext +import net.corda.djvm.rewiring.SandboxClassLoader +import net.corda.djvm.serialization.deserializers.X509CRLDeserializer +import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.serialization.internal.amqp.* +import org.apache.qpid.proton.codec.Data +import java.lang.reflect.Type +import java.security.cert.X509CRL +import java.util.Collections.singleton +import java.util.function.BiFunction +import java.util.function.Function + +class SandboxX509CRLSerializer( + classLoader: SandboxClassLoader, + executor: BiFunction +) : CustomSerializer.Implements(classLoader.loadClassForSandbox(X509CRL::class.java)) { + private val generator: Function + + init { + val generateTask = classLoader.loadClassForSandbox(X509CRLDeserializer::class.java).newInstance() + generator = Function { inputs -> + executor.apply(generateTask, inputs) + } + } + + override val schemaForDocumentation: Schema = Schema(emptyList()) + + override val deserializationAliases: Set> = singleton(X509CRL::class.java) + + override fun readObject(obj: Any, schemas: SerializationSchemas, input: DeserializationInput, context: SerializationContext): Any { + val bits = input.readObject(obj, schemas, ByteArray::class.java, context) as ByteArray + return generator.apply(bits)!! + } + + override fun writeDescribedObject(obj: Any, data: Data, type: Type, output: SerializationOutput, context: SerializationContext) { + abortReadOnly() + } +} diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxX509CertificateSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxX509CertificateSerializer.kt new file mode 100644 index 0000000000..ccb8d3c266 --- /dev/null +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxX509CertificateSerializer.kt @@ -0,0 +1,40 @@ +package net.corda.djvm.serialization.serializers + +import net.corda.core.serialization.SerializationContext +import net.corda.djvm.rewiring.SandboxClassLoader +import net.corda.djvm.serialization.deserializers.X509CertificateDeserializer +import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.serialization.internal.amqp.* +import org.apache.qpid.proton.codec.Data +import java.lang.reflect.Type +import java.security.cert.X509Certificate +import java.util.Collections.singleton +import java.util.function.BiFunction +import java.util.function.Function + +class SandboxX509CertificateSerializer( + classLoader: SandboxClassLoader, + executor: BiFunction +) : CustomSerializer.Implements(classLoader.loadClassForSandbox(X509Certificate::class.java)) { + private val generator: Function + + init { + val generateTask = classLoader.loadClassForSandbox(X509CertificateDeserializer::class.java).newInstance() + generator = Function { inputs -> + executor.apply(generateTask, inputs) + } + } + + override val schemaForDocumentation: Schema = Schema(emptyList()) + + override val deserializationAliases: Set> = singleton(X509Certificate::class.java) + + override fun readObject(obj: Any, schemas: SerializationSchemas, input: DeserializationInput, context: SerializationContext): Any { + val bits = input.readObject(obj, schemas, ByteArray::class.java, context) as ByteArray + return generator.apply(bits)!! + } + + override fun writeDescribedObject(obj: Any, data: Data, type: Type, output: SerializationOutput, context: SerializationContext) { + abortReadOnly() + } +} diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxYearMonthSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxYearMonthSerializer.kt new file mode 100644 index 0000000000..6c91ca9a03 --- /dev/null +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxYearMonthSerializer.kt @@ -0,0 +1,31 @@ +package net.corda.djvm.serialization.serializers + +import net.corda.djvm.rewiring.SandboxClassLoader +import net.corda.djvm.serialization.deserializers.YearMonthDeserializer +import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.serialization.internal.amqp.CustomSerializer +import net.corda.serialization.internal.amqp.SerializerFactory +import net.corda.serialization.internal.amqp.custom.YearMonthSerializer.YearMonthProxy +import java.time.YearMonth +import java.util.Collections.singleton +import java.util.function.BiFunction + +class SandboxYearMonthSerializer( + classLoader: SandboxClassLoader, + private val executor: BiFunction, + factory: SerializerFactory +) : CustomSerializer.Proxy( + clazz = classLoader.loadClassForSandbox(YearMonth::class.java), + proxyClass = classLoader.loadClassForSandbox(YearMonthProxy::class.java), + factory = factory +) { + private val task = classLoader.loadClassForSandbox(YearMonthDeserializer::class.java).newInstance() + + override val deserializationAliases: Set> = singleton(YearMonth::class.java) + + override fun toProxy(obj: Any): Any = abortReadOnly() + + override fun fromProxy(proxy: Any): Any { + return executor.apply(task, proxy)!! + } +} diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxYearSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxYearSerializer.kt new file mode 100644 index 0000000000..3d01eb1ff8 --- /dev/null +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxYearSerializer.kt @@ -0,0 +1,31 @@ +package net.corda.djvm.serialization.serializers + +import net.corda.djvm.rewiring.SandboxClassLoader +import net.corda.djvm.serialization.deserializers.YearDeserializer +import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.serialization.internal.amqp.CustomSerializer +import net.corda.serialization.internal.amqp.SerializerFactory +import net.corda.serialization.internal.amqp.custom.YearSerializer.YearProxy +import java.time.Year +import java.util.Collections.singleton +import java.util.function.BiFunction + +class SandboxYearSerializer( + classLoader: SandboxClassLoader, + private val executor: BiFunction, + factory: SerializerFactory +) : CustomSerializer.Proxy( + clazz = classLoader.loadClassForSandbox(Year::class.java), + proxyClass = classLoader.loadClassForSandbox(YearProxy::class.java), + factory = factory +) { + private val task = classLoader.loadClassForSandbox(YearDeserializer::class.java).newInstance() + + override val deserializationAliases: Set> = singleton(Year::class.java) + + override fun toProxy(obj: Any): Any = abortReadOnly() + + override fun fromProxy(proxy: Any): Any { + return executor.apply(task, proxy)!! + } +} diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxZoneIdSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxZoneIdSerializer.kt new file mode 100644 index 0000000000..6ca73ee520 --- /dev/null +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxZoneIdSerializer.kt @@ -0,0 +1,33 @@ +package net.corda.djvm.serialization.serializers + +import net.corda.djvm.rewiring.SandboxClassLoader +import net.corda.djvm.serialization.deserializers.ZoneIdDeserializer +import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.serialization.internal.amqp.CustomSerializer +import net.corda.serialization.internal.amqp.SerializerFactory +import net.corda.serialization.internal.amqp.custom.ZoneIdSerializer.ZoneIdProxy +import java.time.ZoneId +import java.util.Collections.singleton +import java.util.function.BiFunction + +class SandboxZoneIdSerializer( + classLoader: SandboxClassLoader, + private val executor: BiFunction, + factory: SerializerFactory +) : CustomSerializer.Proxy( + clazz = classLoader.loadClassForSandbox(ZoneId::class.java), + proxyClass = classLoader.loadClassForSandbox(ZoneIdProxy::class.java), + factory = factory +) { + private val task = classLoader.loadClassForSandbox(ZoneIdDeserializer::class.java).newInstance() + + override val revealSubclassesInSchema: Boolean = true + + override val deserializationAliases: Set> = singleton(ZoneId::class.java) + + override fun toProxy(obj: Any): Any = abortReadOnly() + + override fun fromProxy(proxy: Any): Any { + return executor.apply(task, proxy)!! + } +} diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxZonedDateTimeSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxZonedDateTimeSerializer.kt new file mode 100644 index 0000000000..5ef4f04f52 --- /dev/null +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxZonedDateTimeSerializer.kt @@ -0,0 +1,48 @@ +package net.corda.djvm.serialization.serializers + +import net.corda.djvm.rewiring.SandboxClassLoader +import net.corda.djvm.serialization.deserializers.ZonedDateTimeDeserializer +import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.serialization.internal.amqp.CustomSerializer +import net.corda.serialization.internal.amqp.SerializerFactory +import net.corda.serialization.internal.amqp.custom.ZonedDateTimeSerializer.ZonedDateTimeProxy +import java.time.LocalDateTime +import java.time.ZoneId +import java.time.ZoneOffset +import java.time.ZonedDateTime +import java.util.Collections.singleton +import java.util.function.BiFunction + +class SandboxZonedDateTimeSerializer( + classLoader: SandboxClassLoader, + executor: BiFunction, + factory: SerializerFactory +) : CustomSerializer.Proxy( + clazz = classLoader.loadClassForSandbox(ZonedDateTime::class.java), + proxyClass = classLoader.loadClassForSandbox(ZonedDateTimeProxy::class.java), + factory = factory +) { + private val task = classLoader.loadClassForSandbox(ZonedDateTimeDeserializer::class.java).newInstance() + private val creator: BiFunction + + init { + val createTask = clazz.getMethod( + "createDJVM", + classLoader.loadClassForSandbox(LocalDateTime::class.java), + classLoader.loadClassForSandbox(ZoneOffset::class.java), + classLoader.loadClassForSandbox(ZoneId::class.java) + ) + creator = executor.andThen { input -> + @Suppress("unchecked_cast") + createTask(null, *(input as Array))!! + } + } + + override val deserializationAliases: Set> = singleton(ZonedDateTime::class.java) + + override fun toProxy(obj: Any): Any = abortReadOnly() + + override fun fromProxy(proxy: Any): Any { + return creator.apply(task, proxy)!! + } +} diff --git a/src/test/java/greymalkin/ExternalData.java b/src/test/java/greymalkin/ExternalData.java new file mode 100644 index 0000000000..8774478bdb --- /dev/null +++ b/src/test/java/greymalkin/ExternalData.java @@ -0,0 +1,13 @@ +package greymalkin; + +public class ExternalData { + private final String data; + + public ExternalData(String data) { + this.data = data; + } + + public String getData() { + return data; + } +} diff --git a/src/test/java/greymalkin/ExternalEnum.java b/src/test/java/greymalkin/ExternalEnum.java new file mode 100644 index 0000000000..2180693367 --- /dev/null +++ b/src/test/java/greymalkin/ExternalEnum.java @@ -0,0 +1,11 @@ +package greymalkin; + +import net.corda.core.serialization.CordaSerializable; + +@SuppressWarnings("unused") +@CordaSerializable +public enum ExternalEnum { + DOH, + RAY, + ME +} diff --git a/src/test/java/net/corda/djvm/serialization/InnocentData.java b/src/test/java/net/corda/djvm/serialization/InnocentData.java new file mode 100644 index 0000000000..c4c2bd24e8 --- /dev/null +++ b/src/test/java/net/corda/djvm/serialization/InnocentData.java @@ -0,0 +1,22 @@ +package net.corda.djvm.serialization; + +import net.corda.core.serialization.CordaSerializable; + +@CordaSerializable +public class InnocentData { + private final String message; + private final Short number; + + public InnocentData(String message, Short number) { + this.message = message; + this.number = number; + } + + public String getMessage() { + return message; + } + + public Short getNumber() { + return number; + } +} diff --git a/src/test/java/net/corda/djvm/serialization/MultiConstructorData.java b/src/test/java/net/corda/djvm/serialization/MultiConstructorData.java new file mode 100644 index 0000000000..f08b41a148 --- /dev/null +++ b/src/test/java/net/corda/djvm/serialization/MultiConstructorData.java @@ -0,0 +1,53 @@ +package net.corda.djvm.serialization; + +import net.corda.core.serialization.ConstructorForDeserialization; +import net.corda.core.serialization.CordaSerializable; + +@SuppressWarnings({"unused", "WeakerAccess"}) +@CordaSerializable +public class MultiConstructorData { + private final String message; + private final long bigNumber; + private final Character tag; + + @ConstructorForDeserialization + public MultiConstructorData(String message, long bigNumber, Character tag) { + this.message = message; + this.bigNumber = bigNumber; + this.tag = tag; + } + + public MultiConstructorData(String message, long bigNumber) { + this(message, bigNumber, null); + } + + public MultiConstructorData(String message, char tag) { + this(message, 0, tag); + } + + public MultiConstructorData(String message) { + this(message, 0); + } + + public String getMessage() { + return message; + } + + public long getBigNumber() { + return bigNumber; + } + + public Character getTag() { + return tag; + } + + @SuppressWarnings("StringBufferReplaceableByString") + @Override + public String toString() { + return new StringBuilder("MultiConstructor[message='").append(message) + .append("', bigNumber=").append(bigNumber) + .append(", tag=").append(tag) + .append(']') + .toString(); + } +} diff --git a/src/test/java/net/corda/djvm/serialization/VeryEvilData.java b/src/test/java/net/corda/djvm/serialization/VeryEvilData.java new file mode 100644 index 0000000000..1fcbc0dec2 --- /dev/null +++ b/src/test/java/net/corda/djvm/serialization/VeryEvilData.java @@ -0,0 +1,15 @@ +package net.corda.djvm.serialization; + +@SuppressWarnings("unused") +public class VeryEvilData extends InnocentData { + static { + if (!VeryEvilData.class.getName().startsWith("sandbox.")) { + // Execute our evil payload OUTSIDE the sandbox! + throw new IllegalStateException("Victory is mine!"); + } + } + + public VeryEvilData(String message, Short number) { + super(message, number); + } +} diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeBigDecimalTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeBigDecimalTest.kt new file mode 100644 index 0000000000..58dc242a98 --- /dev/null +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeBigDecimalTest.kt @@ -0,0 +1,51 @@ +package net.corda.djvm.serialization + +import net.corda.core.serialization.CordaSerializable +import net.corda.core.serialization.internal._contextSerializationEnv +import net.corda.core.serialization.serialize +import net.corda.djvm.serialization.SandboxType.* +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.junit.jupiter.api.fail +import java.math.BigDecimal +import java.util.function.Function + +@ExtendWith(LocalSerialization::class) +class DeserializeBigDecimalTest : TestBase(KOTLIN) { + companion object { + const val VERY_BIG_DECIMAL = 994349993939.32737232 + } + + @Test + fun `test deserializing big decimal`() { + val bigDecimal = BigDecimalData(BigDecimal.valueOf(VERY_BIG_DECIMAL)) + val data = bigDecimal.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxBigInteger = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowBigDecimal::class.java).newInstance(), + sandboxBigInteger + ) ?: fail("Result cannot be null") + + assertEquals(ShowBigDecimal().apply(bigDecimal), result.toString()) + assertEquals(SANDBOX_STRING, result::class.java.name) + } + } + + class ShowBigDecimal : Function { + override fun apply(data: BigDecimalData): String { + return with(data) { + "BigDecimal: $number" + } + } + } +} + +@CordaSerializable +data class BigDecimalData(val number: BigDecimal) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeBigIntegerTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeBigIntegerTest.kt new file mode 100644 index 0000000000..b89e2443ee --- /dev/null +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeBigIntegerTest.kt @@ -0,0 +1,51 @@ +package net.corda.djvm.serialization + +import net.corda.core.serialization.CordaSerializable +import net.corda.core.serialization.internal._contextSerializationEnv +import net.corda.core.serialization.serialize +import net.corda.djvm.serialization.SandboxType.* +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.junit.jupiter.api.fail +import java.math.BigInteger +import java.util.function.Function + +@ExtendWith(LocalSerialization::class) +class DeserializeBigIntegerTest : TestBase(KOTLIN) { + companion object { + const val VERY_BIG_NUMBER = 1234567890123456789 + } + + @Test + fun `test deserializing big integer`() { + val bigInteger = BigIntegerData(BigInteger.valueOf(VERY_BIG_NUMBER)) + val data = bigInteger.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxBigInteger = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowBigInteger::class.java).newInstance(), + sandboxBigInteger + ) ?: fail("Result cannot be null") + + assertEquals(ShowBigInteger().apply(bigInteger), result.toString()) + assertEquals(SANDBOX_STRING, result::class.java.name) + } + } + + class ShowBigInteger : Function { + override fun apply(data: BigIntegerData): String { + return with(data) { + "BigInteger: $number" + } + } + } +} + +@CordaSerializable +data class BigIntegerData(val number: BigInteger) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeBitSetTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeBitSetTest.kt new file mode 100644 index 0000000000..5b59a1fe4f --- /dev/null +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeBitSetTest.kt @@ -0,0 +1,41 @@ +package net.corda.djvm.serialization + +import net.corda.core.serialization.internal._contextSerializationEnv +import net.corda.core.serialization.serialize +import net.corda.djvm.serialization.SandboxType.* +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.junit.jupiter.api.fail +import java.util.* +import java.util.function.Function + +@ExtendWith(LocalSerialization::class) +class DeserializeBitSetTest : TestBase(KOTLIN) { + @Test + fun `test deserializing bitset`() { + val bitSet = BitSet.valueOf(byteArrayOf(0x00, 0x70, 0x55, 0x3A, 0x48, 0x12)) + val data = bitSet.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxBitSet = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowBitSet::class.java).newInstance(), + sandboxBitSet + ) ?: fail("Result cannot be null") + + assertEquals(bitSet.toString(), result.toString()) + assertEquals(SANDBOX_STRING, result::class.java.name) + } + } + + class ShowBitSet : Function { + override fun apply(bitSet: BitSet): String { + return bitSet.toString() + } + } +} diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeCertificatesTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeCertificatesTest.kt new file mode 100644 index 0000000000..ce8b0b33d5 --- /dev/null +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeCertificatesTest.kt @@ -0,0 +1,135 @@ +package net.corda.djvm.serialization + +import net.corda.core.serialization.internal._contextSerializationEnv +import net.corda.core.serialization.serialize +import net.corda.djvm.serialization.SandboxType.* +import org.assertj.core.api.Assertions.assertThat +import org.bouncycastle.asn1.x509.CRLReason +import org.bouncycastle.asn1.x500.X500Name +import org.bouncycastle.cert.X509v2CRLBuilder +import org.bouncycastle.cert.jcajce.JcaX509CRLConverter +import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.BeforeAll +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.junit.jupiter.api.fail +import java.security.KeyPairGenerator +import java.security.cert.CertPath +import java.security.cert.CertificateFactory +import java.security.cert.X509CRL +import java.security.cert.X509Certificate +import java.util.Date +import java.util.function.Function + +@ExtendWith(LocalSerialization::class) +class DeserializeCertificatesTest : TestBase(KOTLIN) { + companion object { + // The sandbox's localisation may not match that of the host. + // E.g. line separator characters and time zone format. + fun localise(str: String): String { + return str.replace("\n", System.lineSeparator()) + } + + val factory: CertificateFactory = CertificateFactory.getInstance("X.509") + lateinit var certificate: X509Certificate + + @Suppress("unused") + @BeforeAll + @JvmStatic + fun loadCertificate() { + certificate = this::class.java.classLoader.getResourceAsStream("testing.cert")?.use { input -> + factory.generateCertificate(input) as X509Certificate + } ?: fail("Certificate not found") + } + } + + @Test + fun `test deserialize certificate path`() { + val certPath = factory.generateCertPath(listOf(certificate)) + val data = certPath.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxCertPath = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowCertPath::class.java).newInstance(), + sandboxCertPath + ) ?: fail("Result cannot be null") + + assertEquals(ShowCertPath().apply(certPath), localise(result.toString())) + assertThat(result::class.java.name).startsWith("sandbox.") + } + } + + class ShowCertPath : Function { + override fun apply(certPath: CertPath): String { + return "CertPath -> $certPath" + } + } + + @Test + fun `test deserialize X509 certificate`() { + val data = certificate.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxCertificate = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowCertificate::class.java).newInstance(), + sandboxCertificate + ) ?: fail("Result cannot be null") + + assertEquals(ShowCertificate().apply(certificate), localise(result.toString())) + assertThat(result::class.java.name).startsWith("sandbox.") + } + } + + class ShowCertificate : Function { + override fun apply(certificate: X509Certificate): String { + return "X.509 Certificate -> $certificate" + } + } + + @Test + fun `test X509 CRL`() { + val caKeyPair = KeyPairGenerator.getInstance("RSA") + .generateKeyPair() + val signer = JcaContentSignerBuilder("SHA256WithRSAEncryption") + .build(caKeyPair.private) + + val now = Date() + val crl = with(X509v2CRLBuilder(X500Name("CN=Test CA"), now)) { + addCRLEntry(certificate.serialNumber, now, CRLReason.privilegeWithdrawn) + JcaX509CRLConverter().getCRL(build(signer)) + } + val data = crl.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxCRL = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowCRL::class.java).newInstance(), + sandboxCRL + ) ?: fail("Result cannot be null") + + assertEquals(ShowCRL().apply(crl), localise(result.toString())) + assertThat(result::class.java.name).startsWith("sandbox.") + } + } + + class ShowCRL : Function { + override fun apply(crl: X509CRL): String { + return "X.509 CRL -> $crl" + } + } +} diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeClassTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeClassTest.kt new file mode 100644 index 0000000000..13b7a4f30e --- /dev/null +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeClassTest.kt @@ -0,0 +1,60 @@ +package net.corda.djvm.serialization + +import greymalkin.ExternalData +import net.corda.core.serialization.internal._contextSerializationEnv +import net.corda.core.serialization.serialize +import net.corda.djvm.serialization.SandboxType.* +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertThrows +import org.junit.jupiter.api.extension.ExtendWith +import org.junit.jupiter.api.fail +import java.io.NotSerializableException +import java.util.function.Function + +@ExtendWith(LocalSerialization::class) +class DeserializeClassTest : TestBase(KOTLIN) { + @Test + fun `test deserializing existing class`() { + val myClass = ExternalData::class.java + val data = myClass.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxInstant = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowClass::class.java).newInstance(), + sandboxInstant + ) ?: fail("Result cannot be null") + + assertEquals("sandbox.${myClass.name}", result.toString()) + assertEquals(SANDBOX_STRING, result::class.java.name) + } + } + + @Test + fun `test deserializing missing class`() { + // The DJVM will refuse to find this class because it belongs to net.corda.djvm.**. + val myClass = VeryEvilData::class.java + val data = myClass.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val ex = assertThrows{ data.deserializeFor(classLoader) } + assertThat(ex) + .isExactlyInstanceOf(NotSerializableException::class.java) + .hasMessageContaining("VeryEvilData was not found by the node,") + } + } +} + +class ShowClass : Function, String> { + override fun apply(type: Class<*>): String { + return type.name + } +} diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeCollectionsTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeCollectionsTest.kt new file mode 100644 index 0000000000..2548ad88d5 --- /dev/null +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeCollectionsTest.kt @@ -0,0 +1,227 @@ +package net.corda.djvm.serialization + +import greymalkin.ExternalEnum +import net.corda.core.serialization.CordaSerializable +import net.corda.core.serialization.internal._contextSerializationEnv +import net.corda.core.serialization.serialize +import net.corda.core.utilities.NonEmptySet +import net.corda.djvm.serialization.SandboxType.* +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.junit.jupiter.api.fail +import java.util.* +import java.util.function.Function + +@ExtendWith(LocalSerialization::class) +class DeserializeCollectionsTest : TestBase(KOTLIN) { + @Test + fun `test deserializing string list`() { + val stringList = StringList(listOf("Hello", "World", "!")) + val data = stringList.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxList = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowStringList::class.java).newInstance(), + sandboxList + ) ?: fail("Result cannot be null") + + assertEquals(stringList.lines.joinToString(), result.toString()) + assertEquals("Hello, World, !", result.toString()) + } + } + + class ShowStringList : Function { + override fun apply(data: StringList): String { + return data.lines.joinToString() + } + } + + @Test + fun `test deserializing integer set`() { + val integerSet = IntegerSet(linkedSetOf(10, 3, 15, 2, 10)) + val data = integerSet.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxSet = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowIntegerSet::class.java).newInstance(), + sandboxSet + ) ?: fail("Result cannot be null") + + assertEquals(integerSet.numbers.joinToString(), result.toString()) + assertEquals("10, 3, 15, 2", result.toString()) + } + } + + class ShowIntegerSet : Function { + override fun apply(data: IntegerSet): String { + return data.numbers.joinToString() + } + } + + @Test + fun `test deserializing integer sorted set`() { + val integerSortedSet = IntegerSortedSet(sortedSetOf(10, 15, 1000, 3, 2, 10)) + val data = integerSortedSet.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxSet = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowIntegerSortedSet::class.java).newInstance(), + sandboxSet + ) ?: fail("Result cannot be null") + + assertEquals(integerSortedSet.numbers.joinToString(), result.toString()) + assertEquals("2, 3, 10, 15, 1000", result.toString()) + } + } + + class ShowIntegerSortedSet : Function { + override fun apply(data: IntegerSortedSet): String { + return data.numbers.joinToString() + } + } + + @Test + fun `test deserializing long navigable set`() { + val longNavigableSet = LongNavigableSet(sortedSetOf(99955L, 10, 15, 1000, 3, 2, 10)) + val data = longNavigableSet.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxSet = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowLongNavigableSet::class.java).newInstance(), + sandboxSet + ) ?: fail("Result cannot be null") + + assertEquals(longNavigableSet.numbers.joinToString(), result.toString()) + assertEquals("2, 3, 10, 15, 1000, 99955", result.toString()) + } + } + + class ShowLongNavigableSet : Function { + override fun apply(data: LongNavigableSet): String { + return data.numbers.joinToString() + } + } + + @Test + fun `test deserializing short collection`() { + val shortCollection = ShortCollection(listOf(10, 200, 3000)) + val data = shortCollection.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxCollection = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowShortCollection::class.java).newInstance(), + sandboxCollection + ) ?: fail("Result cannot be null") + + assertEquals(shortCollection.numbers.joinToString(), result.toString()) + assertEquals("10, 200, 3000", result.toString()) + } + } + + class ShowShortCollection : Function { + override fun apply(data: ShortCollection): String { + return data.numbers.joinToString() + } + } + + @Test + fun `test deserializing non-empty string set`() { + val nonEmptyStrings = NonEmptyStringSet(NonEmptySet.of("Hello", "World", "!")) + val data = nonEmptyStrings.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxSet = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowNonEmptyStringSet::class.java).newInstance(), + sandboxSet + ) ?: fail("Result cannot be null") + + assertEquals(nonEmptyStrings.lines.joinToString(), result.toString()) + assertEquals("Hello, World, !", result.toString()) + } + } + + class ShowNonEmptyStringSet : Function { + override fun apply(data: NonEmptyStringSet): String { + return data.lines.joinToString() + } + } + + @Test + fun `test deserializing enum set`() { + val enumSet = HasEnumSet(EnumSet.of(ExternalEnum.DOH)) + val data = enumSet.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxSet = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowHasEnumSet::class.java).newInstance(), + sandboxSet + ) ?: fail("Result cannot be null") + + assertEquals(enumSet.values.toString(), result.toString()) + assertEquals("[DOH]", result.toString()) + } + } + + class ShowHasEnumSet : Function { + override fun apply(data: HasEnumSet): String { + return data.values.toString() + } + } +} + +@CordaSerializable +class StringList(val lines: List) + +@CordaSerializable +class IntegerSet(val numbers: Set) + +@CordaSerializable +class IntegerSortedSet(val numbers: SortedSet) + +@CordaSerializable +class LongNavigableSet(val numbers: NavigableSet) + +@CordaSerializable +class ShortCollection(val numbers: Collection) + +@CordaSerializable +class NonEmptyStringSet(val lines: NonEmptySet) + +@CordaSerializable +class HasEnumSet(val values: EnumSet) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeCurrencyTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeCurrencyTest.kt new file mode 100644 index 0000000000..aa5870951e --- /dev/null +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeCurrencyTest.kt @@ -0,0 +1,47 @@ +package net.corda.djvm.serialization + +import net.corda.core.serialization.CordaSerializable +import net.corda.core.serialization.internal._contextSerializationEnv +import net.corda.core.serialization.serialize +import net.corda.djvm.serialization.SandboxType.* +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.junit.jupiter.api.fail +import java.util.* +import java.util.function.Function + +@ExtendWith(LocalSerialization::class) +class DeserializeCurrencyTest : TestBase(KOTLIN) { + @Test + fun `test deserializing currency`() { + val currency = CurrencyData(Currency.getInstance("GBP")) + val data = currency.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxCurrency = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowCurrency::class.java).newInstance(), + sandboxCurrency + ) ?: fail("Result cannot be null") + + assertEquals(ShowCurrency().apply(currency), result.toString()) + assertEquals(SANDBOX_STRING, result::class.java.name) + } + } + + class ShowCurrency : Function { + override fun apply(data: CurrencyData): String { + return with(data) { + "Currency: $currency" + } + } + } +} + +@CordaSerializable +data class CurrencyData(val currency: Currency) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeEnumSetTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeEnumSetTest.kt new file mode 100644 index 0000000000..2dba16c4ed --- /dev/null +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeEnumSetTest.kt @@ -0,0 +1,45 @@ +package net.corda.djvm.serialization + +import greymalkin.ExternalEnum +import net.corda.core.serialization.internal._contextSerializationEnv +import net.corda.core.serialization.serialize +import net.corda.djvm.serialization.SandboxType.KOTLIN +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.extension.ExtendWith +import org.junit.jupiter.api.fail +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.EnumSource +import java.util.* +import java.util.function.Function + +@ExtendWith(LocalSerialization::class) +class DeserializeEnumSetTest : TestBase(KOTLIN) { + @ParameterizedTest + @EnumSource(ExternalEnum::class) + fun `test deserialize enum set`(value: ExternalEnum) { + val enumSet = EnumSet.of(value) + val data = enumSet.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxEnumSet = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowEnumSet::class.java).newInstance(), + sandboxEnumSet + ) ?: fail("Result cannot be null") + + assertEquals(ShowEnumSet().apply(enumSet), result.toString()) + assertEquals("EnumSet: [$value]'", result.toString()) + assertEquals(SANDBOX_STRING, result::class.java.name) + } + } + + class ShowEnumSet : Function, String> { + override fun apply(input: EnumSet<*>): String { + return "EnumSet: $input'" + } + } +} diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeEnumTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeEnumTest.kt new file mode 100644 index 0000000000..2ff7d78e39 --- /dev/null +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeEnumTest.kt @@ -0,0 +1,57 @@ +package net.corda.djvm.serialization + +import net.corda.core.serialization.CordaSerializable +import net.corda.core.serialization.internal._contextSerializationEnv +import net.corda.core.serialization.serialize +import net.corda.djvm.serialization.SandboxType.KOTLIN +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.extension.ExtendWith +import org.junit.jupiter.api.fail +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.EnumSource +import java.util.function.Function + +@ExtendWith(LocalSerialization::class) +class DeserializeEnumTest : TestBase(KOTLIN) { + @ParameterizedTest + @EnumSource(ExampleEnum::class) + fun `test deserialize basic enum`(value: ExampleEnum) { + val example = ExampleData(value) + val data =example.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxExample = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowExampleData::class.java).newInstance(), + sandboxExample + ) ?: fail("Result cannot be null") + + assertEquals(ShowExampleData().apply(example), result.toString()) + assertEquals("Example: name='${value.name}', ordinal='${value.ordinal}'", result.toString()) + assertEquals(SANDBOX_STRING, result::class.java.name) + } + } + + class ShowExampleData : Function { + override fun apply(input: ExampleData): String { + return with(input) { + "Example: name='${value.name}', ordinal='${value.ordinal}'" + } + } + } +} + +@Suppress("unused") +@CordaSerializable +enum class ExampleEnum { + ONE, + TWO, + THREE +} + +@CordaSerializable +data class ExampleData(val value: ExampleEnum) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeGenericsTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeGenericsTest.kt new file mode 100644 index 0000000000..5e887e1b4b --- /dev/null +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeGenericsTest.kt @@ -0,0 +1,81 @@ +package net.corda.djvm.serialization + +import net.corda.core.serialization.CordaSerializable +import net.corda.core.serialization.internal._contextSerializationEnv +import net.corda.core.serialization.serialize +import net.corda.djvm.serialization.SandboxType.* +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.junit.jupiter.api.fail +import java.util.function.Function + +@ExtendWith(LocalSerialization::class) +class DeserializeGenericsTest : TestBase(KOTLIN) { + @Disabled + @Test + fun `test deserializing generic wrapper`() { + val wrappedString = GenericWrapper(data = "Hello World!") + val data = wrappedString.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxWrapper = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowGenericWrapper::class.java).newInstance(), + sandboxWrapper + ) ?: fail("Result cannot be null") + + assertEquals("Hello World!", result.toString()) + assertEquals(SANDBOX_STRING, result::class.java.name) + } + } + + class ShowGenericWrapper : Function, String> { + override fun apply(input: GenericWrapper): String { + return input.data + } + } + + @Test + fun `test deserializing concrete wrapper`() { + val wrapped = ConcreteWrapper( + first = GenericWrapper("Hello World"), + second = GenericWrapper('!') + ) + val data = wrapped.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxWrapped = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowConcreteWrapper::class.java).newInstance(), + sandboxWrapped + ) ?: fail("Result cannot be null") + + assertEquals("Concrete: first='Hello World', second='!'", result.toString()) + } + } + + class ShowConcreteWrapper : Function { + override fun apply(input: ConcreteWrapper): String { + return "Concrete: first='${input.first.data}', second='${input.second.data}'" + } + } +} + +@CordaSerializable +data class GenericWrapper(val data: T) + +@CordaSerializable +data class ConcreteWrapper( + val first: GenericWrapper, + val second: GenericWrapper +) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeInstantTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeInstantTest.kt new file mode 100644 index 0000000000..2316de6dfa --- /dev/null +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeInstantTest.kt @@ -0,0 +1,41 @@ +package net.corda.djvm.serialization + +import net.corda.core.serialization.internal._contextSerializationEnv +import net.corda.core.serialization.serialize +import net.corda.djvm.serialization.SandboxType.* +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.junit.jupiter.api.fail +import java.time.Instant +import java.util.function.Function + +@ExtendWith(LocalSerialization::class) +class DeserializeInstantTest : TestBase(KOTLIN) { + @Test + fun `test deserializing instant`() { + val instant = Instant.now() + val data = instant.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxInstant = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowInstant::class.java).newInstance(), + sandboxInstant + ) ?: fail("Result cannot be null") + + assertEquals(instant.toString(), result.toString()) + assertEquals(SANDBOX_STRING, result::class.java.name) + } + } + + class ShowInstant : Function { + override fun apply(instant: Instant): String { + return instant.toString() + } + } +} diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeJavaWithMultipleConstructorsTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeJavaWithMultipleConstructorsTest.kt new file mode 100644 index 0000000000..719d28a03e --- /dev/null +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeJavaWithMultipleConstructorsTest.kt @@ -0,0 +1,41 @@ +package net.corda.djvm.serialization + +import net.corda.core.serialization.internal._contextSerializationEnv +import net.corda.core.serialization.serialize +import net.corda.djvm.serialization.SandboxType.* +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.junit.jupiter.api.fail + +import java.util.function.Function + +@ExtendWith(LocalSerialization::class) +class DeserializeJavaWithMultipleConstructorsTest : TestBase(KOTLIN) { + @Test + fun `test deserializing existing class`() { + val multiData = MultiConstructorData("Hello World", Long.MAX_VALUE, '!') + val data = multiData.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxData = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowMultiData::class.java).newInstance(), + sandboxData + ) ?: fail("Result cannot be null") + + assertThat(result.toString()) + .isEqualTo("MultiConstructor[message='Hello World', bigNumber=9223372036854775807, tag=!]") + } + } + + class ShowMultiData : Function { + override fun apply(data: MultiConstructorData): String { + return data.toString() + } + } +} diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeLocalDateTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeLocalDateTest.kt new file mode 100644 index 0000000000..007ca86548 --- /dev/null +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeLocalDateTest.kt @@ -0,0 +1,41 @@ +package net.corda.djvm.serialization + +import net.corda.core.serialization.internal._contextSerializationEnv +import net.corda.core.serialization.serialize +import net.corda.djvm.serialization.SandboxType.* +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.junit.jupiter.api.fail +import java.time.LocalDate +import java.util.function.Function + +@ExtendWith(LocalSerialization::class) +class DeserializeLocalDateTest : TestBase(KOTLIN) { + @Test + fun `test deserializing local date`() { + val date = LocalDate.now() + val data = date.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxDate = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowLocalDate::class.java).newInstance(), + sandboxDate + ) ?: fail("Result cannot be null") + + assertEquals(date.toString(), result.toString()) + assertEquals(SANDBOX_STRING, result::class.java.name) + } + } + + class ShowLocalDate : Function { + override fun apply(date: LocalDate): String { + return date.toString() + } + } +} diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeLocalDateTimeTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeLocalDateTimeTest.kt new file mode 100644 index 0000000000..1dd9debfbe --- /dev/null +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeLocalDateTimeTest.kt @@ -0,0 +1,41 @@ +package net.corda.djvm.serialization + +import net.corda.core.serialization.internal._contextSerializationEnv +import net.corda.core.serialization.serialize +import net.corda.djvm.serialization.SandboxType.* +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.junit.jupiter.api.fail +import java.time.LocalDateTime +import java.util.function.Function + +@ExtendWith(LocalSerialization::class) +class DeserializeLocalDateTimeTest : TestBase(KOTLIN) { + @Test + fun `test deserializing local date-time`() { + val dateTime = LocalDateTime.now() + val data = dateTime.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxDateTime = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowLocalDateTime::class.java).newInstance(), + sandboxDateTime + ) ?: fail("Result cannot be null") + + assertEquals(dateTime.toString(), result.toString()) + assertEquals(SANDBOX_STRING, result::class.java.name) + } + } + + class ShowLocalDateTime : Function { + override fun apply(dateTime: LocalDateTime): String { + return dateTime.toString() + } + } +} diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeLocalTimeTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeLocalTimeTest.kt new file mode 100644 index 0000000000..2bfb4c2956 --- /dev/null +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeLocalTimeTest.kt @@ -0,0 +1,41 @@ +package net.corda.djvm.serialization + +import net.corda.core.serialization.internal._contextSerializationEnv +import net.corda.core.serialization.serialize +import net.corda.djvm.serialization.SandboxType.* +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.junit.jupiter.api.fail +import java.time.LocalTime +import java.util.function.Function + +@ExtendWith(LocalSerialization::class) +class DeserializeLocalTimeTest : TestBase(KOTLIN) { + @Test + fun `test deserializing local time`() { + val time = LocalTime.now() + val data = time.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxTime = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowLocalTime::class.java).newInstance(), + sandboxTime + ) ?: fail("Result cannot be null") + + assertEquals(time.toString(), result.toString()) + assertEquals(SANDBOX_STRING, result::class.java.name) + } + } + + class ShowLocalTime : Function { + override fun apply(time: LocalTime): String { + return time.toString() + } + } +} diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeMapsTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeMapsTest.kt new file mode 100644 index 0000000000..b4f8d692ef --- /dev/null +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeMapsTest.kt @@ -0,0 +1,211 @@ +package net.corda.djvm.serialization + +import net.corda.core.serialization.CordaSerializable +import net.corda.core.serialization.internal._contextSerializationEnv +import net.corda.core.serialization.serialize +import net.corda.djvm.serialization.SandboxType.* +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.junit.jupiter.api.fail +import java.util.* +import java.util.function.Function + +@ExtendWith(LocalSerialization::class) +class DeserializeMapsTest : TestBase(KOTLIN) { + @Test + fun `test deserializing map`() { + val stringMap = StringMap(mapOf("Open" to "Hello World", "Close" to "Goodbye, Cruel World")) + val data = stringMap.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxMap = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowStringMap::class.java).newInstance(), + sandboxMap + ) ?: fail("Result cannot be null") + + assertEquals(stringMap.values.entries.joinToString(), result.toString()) + assertEquals("Open=Hello World, Close=Goodbye, Cruel World", result.toString()) + } + } + + class ShowStringMap : Function { + override fun apply(data: StringMap): String { + return data.values.entries.joinToString() + } + } + + @Test + fun `test deserializing sorted map`() { + val sortedMap = StringSortedMap(sortedMapOf( + 100 to "Goodbye, Cruel World", + 10 to "Hello World", + 50 to "Having Fun!" + )) + val data = sortedMap.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxMap = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowStringSortedMap::class.java).newInstance(), + sandboxMap + ) ?: fail("Result cannot be null") + + assertEquals(sortedMap.values.entries.joinToString(), result.toString()) + assertEquals("10=Hello World, 50=Having Fun!, 100=Goodbye, Cruel World", result.toString()) + } + } + + class ShowStringSortedMap : Function { + override fun apply(data: StringSortedMap): String { + return data.values.entries.joinToString() + } + } + + @Test + fun `test deserializing navigable map`() { + val navigableMap = StringNavigableMap(mapOf( + 10000L to "Goodbye, Cruel World", + 1000L to "Hello World", + 5000L to "Having Fun!" + ).toMap(TreeMap())) + val data = navigableMap.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxMap = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowStringNavigableMap::class.java).newInstance(), + sandboxMap + ) ?: fail("Result cannot be null") + + assertEquals(navigableMap.values.entries.joinToString(), result.toString()) + assertEquals("1000=Hello World, 5000=Having Fun!, 10000=Goodbye, Cruel World", result.toString()) + } + } + + class ShowStringNavigableMap : Function { + override fun apply(data: StringNavigableMap): String { + return data.values.entries.joinToString() + } + } + + @Test + fun `test deserializing linked hash map`() { + val linkedHashMap = StringLinkedHashMap(linkedMapOf( + "Close" to "Goodbye, Cruel World", + "Open" to "Hello World", + "During" to "Having Fun!" + )) + val data = linkedHashMap.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxMap = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowStringLinkedHashMap::class.java).newInstance(), + sandboxMap + ) ?: fail("Result cannot be null") + + assertEquals(linkedHashMap.values.entries.joinToString(), result.toString()) + assertEquals("Close=Goodbye, Cruel World, Open=Hello World, During=Having Fun!", result.toString()) + } + } + + class ShowStringLinkedHashMap : Function { + override fun apply(data: StringLinkedHashMap): String { + return data.values.entries.joinToString() + } + } + + @Test + fun `test deserializing tree map`() { + val treeMap = StringTreeMap(mapOf( + 10000 to "Goodbye, Cruel World", + 1000 to "Hello World", + 5000 to "Having Fun!" + ).toMap(TreeMap())) + val data = treeMap.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxMap = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowStringTreeMap::class.java).newInstance(), + sandboxMap + ) ?: fail("Result cannot be null") + + assertEquals(treeMap.values.entries.joinToString(), result.toString()) + assertEquals("1000=Hello World, 5000=Having Fun!, 10000=Goodbye, Cruel World", result.toString()) + } + } + + class ShowStringTreeMap : Function { + override fun apply(data: StringTreeMap): String { + return data.values.entries.joinToString() + } + } + + @Test + fun `test deserializing enum map`() { + val enumMap = EnumMap(mapOf( + ExampleEnum.ONE to "One!", + ExampleEnum.TWO to "Two!" + )) + val data = enumMap.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxMap = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowEnumMap::class.java).newInstance(), + sandboxMap + ) ?: fail("Result cannot be null") + + assertEquals(enumMap.toString(), result.toString()) + assertEquals("{ONE=One!, TWO=Two!}", result.toString()) + } + } + + class ShowEnumMap : Function, String> { + override fun apply(data: EnumMap<*, String>): String { + return data.toString() + } + } +} + +@CordaSerializable +class StringMap(val values: Map) + +@CordaSerializable +class StringSortedMap(val values: SortedMap) + +@CordaSerializable +class StringNavigableMap(val values: NavigableMap) + +@CordaSerializable +class StringLinkedHashMap(val values: LinkedHashMap) + +@CordaSerializable +class StringTreeMap(val values: TreeMap) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeMonthDayTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeMonthDayTest.kt new file mode 100644 index 0000000000..b9e7fac533 --- /dev/null +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeMonthDayTest.kt @@ -0,0 +1,41 @@ +package net.corda.djvm.serialization + +import net.corda.core.serialization.internal._contextSerializationEnv +import net.corda.core.serialization.serialize +import net.corda.djvm.serialization.SandboxType.* +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.junit.jupiter.api.fail +import java.time.MonthDay +import java.util.function.Function + +@ExtendWith(LocalSerialization::class) +class DeserializeMonthDayTest : TestBase(KOTLIN) { + @Test + fun `test deserializing month-day`() { + val monthDay = MonthDay.now() + val data = monthDay.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxMonthDay = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowMonthDay::class.java).newInstance(), + sandboxMonthDay + ) ?: fail("Result cannot be null") + + assertEquals(monthDay.toString(), result.toString()) + assertEquals(SANDBOX_STRING, result::class.java.name) + } + } + + class ShowMonthDay : Function { + override fun apply(monthDay: MonthDay): String { + return monthDay.toString() + } + } +} diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeObjectArraysTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeObjectArraysTest.kt new file mode 100644 index 0000000000..b1b1a74928 --- /dev/null +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeObjectArraysTest.kt @@ -0,0 +1,318 @@ +package net.corda.djvm.serialization + +import net.corda.core.serialization.CordaSerializable +import net.corda.core.serialization.internal._contextSerializationEnv +import net.corda.core.serialization.serialize +import net.corda.djvm.serialization.SandboxType.* +import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.junit.jupiter.api.fail +import java.util.* +import java.util.function.Function + +@ExtendWith(LocalSerialization::class) +class DeserializeObjectArraysTest : TestBase(KOTLIN) { + @Test + fun `test deserializing string array`() { + val stringArray = HasStringArray(arrayOf("Hello", "World", "!")) + val data = stringArray.serialize() + assertEquals("Hello, World, !", ShowStringArray().apply(stringArray)) + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxArray = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowStringArray::class.java).newInstance(), + sandboxArray + ) ?: fail("Result cannot be null") + + assertEquals(SANDBOX_STRING, result::class.java.name) + assertEquals("Hello, World, !", result.toString()) + } + } + + class ShowStringArray : Function { + override fun apply(data: HasStringArray): String { + return data.lines.joinToString() + } + } + + @Test + fun `test deserializing character array`() { + val charArray = HasCharacterArray(arrayOf('H', 'e', 'l', 'l', 'o', '!')) + val data = charArray.serialize() + assertEquals("Hello!", ShowCharacterArray().apply(charArray)) + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxArray = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowCharacterArray::class.java).newInstance(), + sandboxArray + ) ?: fail("Result cannot be null") + + assertEquals(SANDBOX_STRING, result::class.java.name) + assertEquals("Hello!", result.toString()) + } + } + + class ShowCharacterArray : Function { + override fun apply(data: HasCharacterArray): String { + return data.letters.joinTo(StringBuilder(), separator = "").toString() + } + } + + @Test + fun `test deserializing long array`() { + val longArray = HasLongArray(arrayOf(1000, 2000, 3000, 4000, 5000)) + val data = longArray.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxArray = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowLongArray::class.java).newInstance(), + sandboxArray + ) ?: fail("Result cannot be null") + + assertEquals("sandbox.java.lang.Long", result::class.java.name) + assertEquals("15000", result.toString()) + } + } + + class ShowLongArray : Function { + override fun apply(data: HasLongArray): Long { + return data.longs.sum() + } + } + + @Test + fun `test deserializing integer array`() { + val integerArray = HasIntegerArray(arrayOf(100, 200, 300, 400, 500)) + val data = integerArray.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxArray = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowIntegerArray::class.java).newInstance(), + sandboxArray + ) ?: fail("Result cannot be null") + + assertEquals("sandbox.java.lang.Integer", result::class.java.name) + assertEquals("1500", result.toString()) + } + } + + class ShowIntegerArray : Function { + override fun apply(data: HasIntegerArray): Int { + return data.integers.sum() + } + } + + @Test + fun `test deserializing short array`() { + val shortArray = HasShortArray(arrayOf(100, 200, 300, 400, 500)) + val data = shortArray.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxArray = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowShortArray::class.java).newInstance(), + sandboxArray + ) ?: fail("Result cannot be null") + + assertEquals("sandbox.java.lang.Integer", result::class.java.name) + assertEquals("1500", result.toString()) + } + } + + class ShowShortArray : Function { + override fun apply(data: HasShortArray): Int { + return data.shorts.sum() + } + } + + @Test + fun `test deserializing byte array`() { + val byteArray = HasByteArray(arrayOf(10, 20, 30, 40, 50)) + val data = byteArray.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxArray = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowByteArray::class.java).newInstance(), + sandboxArray + ) ?: fail("Result cannot be null") + + assertEquals("sandbox.java.lang.Integer", result::class.java.name) + assertEquals("150", result.toString()) + } + } + + class ShowByteArray : Function { + override fun apply(data: HasByteArray): Int { + return data.bytes.sum() + } + } + + @Test + fun `test deserializing double array`() { + val doubleArray = HasDoubleArray(arrayOf(1000.0, 2000.0, 3000.0, 4000.0, 5000.0)) + val data = doubleArray.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxArray = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowDoubleArray::class.java).newInstance(), + sandboxArray + ) ?: fail("Result cannot be null") + + assertEquals("sandbox.java.lang.Double", result::class.java.name) + assertEquals("15000.0", result.toString()) + } + } + + class ShowDoubleArray : Function { + override fun apply(data: HasDoubleArray): Double { + return data.doubles.sum() + } + } + + @Test + fun `test deserializing float array`() { + val floatArray = HasFloatArray(arrayOf(10.0f, 20.0f, 30.0f, 40.0f, 50.0f)) + val data = floatArray.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxArray = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowFloatArray::class.java).newInstance(), + sandboxArray + ) ?: fail("Result cannot be null") + + assertEquals("sandbox.java.lang.Float", result::class.java.name) + assertEquals("150.0", result.toString()) + } + } + + class ShowFloatArray : Function { + override fun apply(data: HasFloatArray): Float { + return data.floats.sum() + } + } + + @Test + fun `test deserializing boolean array`() { + val booleanArray = HasBooleanArray(arrayOf(true, true, true)) + val data = booleanArray.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxArray = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowBooleanArray::class.java).newInstance(), + sandboxArray + ) ?: fail("Result cannot be null") + + assertEquals("sandbox.java.lang.Boolean", result::class.java.name) + assertEquals("true", result.toString()) + } + } + + class ShowBooleanArray : Function { + override fun apply(data: HasBooleanArray): Boolean { + return data.bools.all { it } + } + } + + @Test + fun `test deserializing uuid array`() { + val uuid = UUID.randomUUID() + val uuidArray = HasUUIDArray(arrayOf(uuid)) + val data = uuidArray.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxArray = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowUUIDArray::class.java).newInstance(), + sandboxArray + ) ?: fail("Result cannot be null") + + assertEquals(SANDBOX_STRING, result::class.java.name) + assertEquals(uuid.toString(), result.toString()) + } + } + + class ShowUUIDArray : Function { + override fun apply(data: HasUUIDArray): String { + return data.uuids.joinTo(StringBuilder()).toString() + } + } +} + +@CordaSerializable +class HasStringArray(val lines: Array) + +@CordaSerializable +class HasCharacterArray(val letters: Array) + +@CordaSerializable +class HasLongArray(val longs: Array) + +@CordaSerializable +class HasIntegerArray(val integers: Array) + +@CordaSerializable +class HasShortArray(val shorts: Array) + +@CordaSerializable +class HasByteArray(val bytes: Array) + +@CordaSerializable +class HasDoubleArray(val doubles: Array) + +@CordaSerializable +class HasFloatArray(val floats: Array) + +@CordaSerializable +class HasBooleanArray(val bools: Array) + +@CordaSerializable +class HasUUIDArray(val uuids: Array) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeOffsetDateTimeTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeOffsetDateTimeTest.kt new file mode 100644 index 0000000000..cfc004522e --- /dev/null +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeOffsetDateTimeTest.kt @@ -0,0 +1,41 @@ +package net.corda.djvm.serialization + +import net.corda.core.serialization.internal._contextSerializationEnv +import net.corda.core.serialization.serialize +import net.corda.djvm.serialization.SandboxType.* +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.junit.jupiter.api.fail +import java.time.OffsetDateTime +import java.util.function.Function + +@ExtendWith(LocalSerialization::class) +class DeserializeOffsetDateTimeTest : TestBase(KOTLIN) { + @Test + fun `test deserializing offset date-time`() { + val dateTime = OffsetDateTime.now() + val data = dateTime.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxDateTime = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowOffsetDateTime::class.java).newInstance(), + sandboxDateTime + ) ?: fail("Result cannot be null") + + assertEquals(dateTime.toString(), result.toString()) + assertEquals(SANDBOX_STRING, result::class.java.name) + } + } + + class ShowOffsetDateTime : Function { + override fun apply(dateTime: OffsetDateTime): String { + return dateTime.toString() + } + } +} diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeOffsetTimeTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeOffsetTimeTest.kt new file mode 100644 index 0000000000..a9eaad89f4 --- /dev/null +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeOffsetTimeTest.kt @@ -0,0 +1,41 @@ +package net.corda.djvm.serialization + +import net.corda.core.serialization.internal._contextSerializationEnv +import net.corda.core.serialization.serialize +import net.corda.djvm.serialization.SandboxType.* +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.junit.jupiter.api.fail +import java.time.OffsetTime +import java.util.function.Function + +@ExtendWith(LocalSerialization::class) +class DeserializeOffsetTimeTest : TestBase(KOTLIN) { + @Test + fun `test deserializing instant`() { + val time = OffsetTime.now() + val data = time.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxTime = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowOffsetTime::class.java).newInstance(), + sandboxTime + ) ?: fail("Result cannot be null") + + assertEquals(time.toString(), result.toString()) + assertEquals(SANDBOX_STRING, result::class.java.name) + } + } + + class ShowOffsetTime : Function { + override fun apply(time: OffsetTime): String { + return time.toString() + } + } +} diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeOptionalTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeOptionalTest.kt new file mode 100644 index 0000000000..8104f282ab --- /dev/null +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeOptionalTest.kt @@ -0,0 +1,62 @@ +package net.corda.djvm.serialization + +import net.corda.core.serialization.internal._contextSerializationEnv +import net.corda.core.serialization.serialize +import net.corda.djvm.serialization.SandboxType.* +import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.junit.jupiter.api.fail +import java.util.* +import java.util.function.Function + +@ExtendWith(LocalSerialization::class) +class DeserializeOptionalTest : TestBase(KOTLIN) { + @Test + fun `test deserializing optional with object`() { + val optional = Optional.of("Hello World!") + val data = optional.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxOptional = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowOptional::class.java).newInstance(), + sandboxOptional + ) ?: fail("Result cannot be null") + + assertEquals("Optional -> Optional[Hello World!]", result.toString()) + assertEquals(SANDBOX_STRING, result::class.java.name) + } + } + + @Test + fun `test deserializing optional without object`() { + val optional = Optional.empty() + val data = optional.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxOptional = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowOptional::class.java).newInstance(), + sandboxOptional + ) ?: fail("Result cannot be null") + + assertEquals("Optional -> Optional.empty", result.toString()) + assertEquals(SANDBOX_STRING, result::class.java.name) + } + } +} + +class ShowOptional : Function, String> { + override fun apply(optional: Optional<*>): String { + return "Optional -> $optional" + } +} diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializePeriodTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializePeriodTest.kt new file mode 100644 index 0000000000..2784dbd8aa --- /dev/null +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializePeriodTest.kt @@ -0,0 +1,41 @@ +package net.corda.djvm.serialization + +import net.corda.core.serialization.internal._contextSerializationEnv +import net.corda.core.serialization.serialize +import net.corda.djvm.serialization.SandboxType.* +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.junit.jupiter.api.fail +import java.time.Period +import java.util.function.Function + +@ExtendWith(LocalSerialization::class) +class DeserializePeriodTest : TestBase(KOTLIN) { + @Test + fun `test deserializing period`() { + val period = Period.of(1, 2, 3) + val data = period.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxPeriod = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowPeriod::class.java).newInstance(), + sandboxPeriod + ) ?: fail("Result cannot be null") + + assertEquals(period.toString(), result.toString()) + assertEquals(SANDBOX_STRING, result::class.java.name) + } + } + + class ShowPeriod : Function { + override fun apply(period: Period): String { + return period.toString() + } + } +} diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializePrimitiveArraysTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializePrimitiveArraysTest.kt new file mode 100644 index 0000000000..4cb3b4b30a --- /dev/null +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializePrimitiveArraysTest.kt @@ -0,0 +1,255 @@ +package net.corda.djvm.serialization + +import net.corda.core.serialization.CordaSerializable +import net.corda.core.serialization.internal._contextSerializationEnv +import net.corda.core.serialization.serialize +import net.corda.djvm.serialization.SandboxType.* +import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.junit.jupiter.api.fail +import java.util.function.Function + +@ExtendWith(LocalSerialization::class) +class DeserializePrimitiveArraysTest : TestBase(KOTLIN) { + @Test + fun `test deserializing character array`() { + val charArray = PrimitiveCharArray(charArrayOf('H', 'e', 'l', 'l', 'o', '!')) + val data = charArray.serialize() + assertEquals("Hello!", ShowCharArray().apply(charArray)) + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxArray = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowCharArray::class.java).newInstance(), + sandboxArray + ) ?: fail("Result cannot be null") + + assertEquals(SANDBOX_STRING, result::class.java.name) + assertEquals("Hello!", result.toString()) + } + } + + class ShowCharArray : Function { + override fun apply(data: PrimitiveCharArray): String { + return data.letters.joinTo(StringBuilder(), separator = "").toString() + } + } + + @Test + fun `test deserializing integer array`() { + val intArray = PrimitiveIntegerArray(intArrayOf(100, 200, 300, 400, 500)) + val data = intArray.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxArray = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowIntegerArray::class.java).newInstance(), + sandboxArray + ) ?: fail("Result cannot be null") + + assertEquals("sandbox.java.lang.Integer", result::class.java.name) + assertEquals("1500", result.toString()) + } + } + + class ShowIntegerArray : Function { + override fun apply(data: PrimitiveIntegerArray): Int { + return data.integers.sum() + } + } + + @Test + fun `test deserializing long array`() { + val longArray = PrimitiveLongArray(longArrayOf(1000, 2000, 3000, 4000, 5000)) + val data = longArray.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxArray = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowLongArray::class.java).newInstance(), + sandboxArray + ) ?: fail("Result cannot be null") + + assertEquals("sandbox.java.lang.Long", result::class.java.name) + assertEquals("15000", result.toString()) + } + } + + class ShowLongArray : Function { + override fun apply(data: PrimitiveLongArray): Long { + return data.longs.sum() + } + } + + @Test + fun `test deserializing short array`() { + val shortArray = PrimitiveShortArray(shortArrayOf(100, 200, 300, 400, 500)) + val data = shortArray.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxArray = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowShortArray::class.java).newInstance(), + sandboxArray + ) ?: fail("Result cannot be null") + + assertEquals("sandbox.java.lang.Integer", result::class.java.name) + assertEquals("1500", result.toString()) + } + } + + class ShowShortArray : Function { + override fun apply(data: PrimitiveShortArray): Int { + return data.shorts.sum() + } + } + + @Test + fun `test deserializing byte array`() { + val byteArray = PrimitiveByteArray(byteArrayOf(10, 20, 30, 40, 50)) + val data = byteArray.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxArray = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowByteArray::class.java).newInstance(), + sandboxArray + ) ?: fail("Result cannot be null") + + assertEquals("sandbox.java.lang.Integer", result::class.java.name) + assertEquals("150", result.toString()) + } + } + + class ShowByteArray : Function { + override fun apply(data: PrimitiveByteArray): Int { + return data.bytes.sum() + } + } + + @Test + fun `test deserializing boolean array`() { + val booleanArray = PrimitiveBooleanArray(booleanArrayOf(true, true)) + val data = booleanArray.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxArray = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowBooleanArray::class.java).newInstance(), + sandboxArray + ) ?: fail("Result cannot be null") + + assertEquals("sandbox.java.lang.Boolean", result::class.java.name) + assertEquals("true", result.toString()) + } + } + + class ShowBooleanArray : Function { + override fun apply(data: PrimitiveBooleanArray): Boolean { + return data.bools.all { it } + } + } + + @Test + fun `test deserializing double array`() { + val doubleArray = PrimitiveDoubleArray(doubleArrayOf(1000.0, 2000.0, 3000.0, 4000.0, 5000.0)) + val data = doubleArray.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxArray = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowDoubleArray::class.java).newInstance(), + sandboxArray + ) ?: fail("Result cannot be null") + + assertEquals("sandbox.java.lang.Double", result::class.java.name) + assertEquals("15000.0", result.toString()) + } + } + + class ShowDoubleArray : Function { + override fun apply(data: PrimitiveDoubleArray): Double { + return data.doubles.sum() + } + } + + @Test + fun `test deserializing float array`() { + val floatArray = PrimitiveFloatArray(floatArrayOf(100.0f, 200.0f, 300.0f, 400.0f, 500.0f)) + val data = floatArray.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxArray = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowFloatArray::class.java).newInstance(), + sandboxArray + ) ?: fail("Result cannot be null") + + assertEquals("sandbox.java.lang.Float", result::class.java.name) + assertEquals("1500.0", result.toString()) + } + } + + class ShowFloatArray : Function { + override fun apply(data: PrimitiveFloatArray): Float { + return data.floats.sum() + } + } +} + +@CordaSerializable +class PrimitiveCharArray(val letters: CharArray) + +@CordaSerializable +class PrimitiveShortArray(val shorts: ShortArray) + +@CordaSerializable +class PrimitiveIntegerArray(val integers: IntArray) + +@CordaSerializable +class PrimitiveLongArray(val longs: LongArray) + +@CordaSerializable +class PrimitiveByteArray(val bytes: ByteArray) + +@CordaSerializable +class PrimitiveBooleanArray(val bools: BooleanArray) + +@CordaSerializable +class PrimitiveDoubleArray(val doubles: DoubleArray) + +@CordaSerializable +class PrimitiveFloatArray(val floats: FloatArray) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializePrimitivesTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializePrimitivesTest.kt new file mode 100644 index 0000000000..894cb2a392 --- /dev/null +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializePrimitivesTest.kt @@ -0,0 +1,75 @@ +package net.corda.djvm.serialization + +import net.corda.core.serialization.CordaSerializable +import net.corda.core.serialization.internal._contextSerializationEnv +import net.corda.core.serialization.serialize +import net.corda.djvm.serialization.SandboxType.* +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import java.util.* + +@ExtendWith(LocalSerialization::class) +class DeserializePrimitivesTest : TestBase(KOTLIN) { + @Test + fun `test naked uuid`() { + val uuid = UUID.randomUUID() + val data = uuid.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxUUID = data.deserializeFor(classLoader) + assertEquals(uuid.toString(), sandboxUUID.toString()) + assertEquals("sandbox.${uuid::class.java.name}", sandboxUUID::class.java.name) + } + } + + @Test + fun `test wrapped uuid`() { + val uuid = WrappedUUID(UUID.randomUUID()) + val data = uuid.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxUUID = data.deserializeFor(classLoader) + assertEquals(uuid.toString(), sandboxUUID.toString()) + assertEquals("sandbox.${uuid::class.java.name}", sandboxUUID::class.java.name) + } + } + + @Test + fun `test naked date`() { + val now = Date() + val data = now.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxNow = data.deserializeFor(classLoader) + assertEquals(now.toString(), sandboxNow.toString()) + assertEquals("sandbox.${now::class.java.name}", sandboxNow::class.java.name) + } + } + + @Test + fun `test wrapped date`() { + val now = WrappedDate(Date()) + val data = now.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxNow = data.deserializeFor(classLoader) + assertEquals(now.toString(), sandboxNow.toString()) + assertEquals("sandbox.${now::class.java.name}", sandboxNow::class.java.name) + } + } +} + +@CordaSerializable +data class WrappedUUID(val uuid: UUID) + +@CordaSerializable +data class WrappedDate(val date: Date) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeProtonJTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeProtonJTest.kt new file mode 100644 index 0000000000..2de052b5d1 --- /dev/null +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeProtonJTest.kt @@ -0,0 +1,254 @@ +package net.corda.djvm.serialization + +import net.corda.core.serialization.CordaSerializable +import net.corda.core.serialization.internal._contextSerializationEnv +import net.corda.core.serialization.serialize +import net.corda.djvm.serialization.SandboxType.* +import org.apache.qpid.proton.amqp.* +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.junit.jupiter.api.fail +import java.util.function.Function + +@ExtendWith(LocalSerialization::class) +class DeserializeProtonJTest : TestBase(KOTLIN) { + @Test + fun `test deserializing unsigned long`() { + val protonJ = HasUnsignedLong(UnsignedLong.valueOf(12345678)) + val data = protonJ.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxProtonJ = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowUnsignedLong::class.java).newInstance(), + sandboxProtonJ + ) ?: fail("Result cannot be null") + + assertEquals(protonJ.number.toString(), result.toString()) + assertEquals(SANDBOX_STRING, result::class.java.name) + } + } + + class ShowUnsignedLong : Function { + override fun apply(data: HasUnsignedLong): String { + return data.number.toString() + } + } + + @Test + fun `test deserializing unsigned integer`() { + val protonJ = HasUnsignedInteger(UnsignedInteger.valueOf(123456)) + val data = protonJ.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxProtonJ = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowUnsignedInteger::class.java).newInstance(), + sandboxProtonJ + ) ?: fail("Result cannot be null") + + assertEquals(protonJ.number.toString(), result.toString()) + assertEquals(SANDBOX_STRING, result::class.java.name) + } + } + + class ShowUnsignedInteger : Function { + override fun apply(data: HasUnsignedInteger): String { + return data.number.toString() + } + } + + @Test + fun `test deserializing unsigned short`() { + val protonJ = HasUnsignedShort(UnsignedShort.valueOf(12345)) + val data = protonJ.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxProtonJ = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowUnsignedShort::class.java).newInstance(), + sandboxProtonJ + ) ?: fail("Result cannot be null") + + assertEquals(protonJ.number.toString(), result.toString()) + assertEquals(SANDBOX_STRING, result::class.java.name) + } + } + + class ShowUnsignedShort : Function { + override fun apply(data: HasUnsignedShort): String { + return data.number.toString() + } + } + + @Test + fun `test deserializing unsigned byte`() { + val protonJ = HasUnsignedByte(UnsignedByte.valueOf(0x8f.toByte())) + val data = protonJ.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxProtonJ = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowUnsignedByte::class.java).newInstance(), + sandboxProtonJ + ) ?: fail("Result cannot be null") + + assertEquals(protonJ.number.toString(), result.toString()) + assertEquals(SANDBOX_STRING, result::class.java.name) + } + } + + class ShowUnsignedByte : Function { + override fun apply(data: HasUnsignedByte): String { + return data.number.toString() + } + } + + @Test + fun `test deserializing 128 bit decimal`() { + val protonJ = HasDecimal128(Decimal128(12345678, 98765432)) + val data = protonJ.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxProtonJ = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowDecimal128::class.java).newInstance(), + sandboxProtonJ + ) ?: fail("Result cannot be null") + + assertThat(result) + .isEqualTo(protonJ.number.let { longArrayOf(it.mostSignificantBits, it.leastSignificantBits) }) + } + } + + class ShowDecimal128 : Function { + override fun apply(data: HasDecimal128): LongArray { + return data.number.let { longArrayOf(it.mostSignificantBits, it.leastSignificantBits) } + } + } + + @Test + fun `test deserializing 64 bit decimal`() { + val protonJ = HasDecimal64(Decimal64(98765432)) + val data = protonJ.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxProtonJ = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowDecimal64::class.java).newInstance(), + sandboxProtonJ + ) ?: fail("Result cannot be null") + + assertEquals(protonJ.number.bits.toString(), result.toString()) + } + } + + class ShowDecimal64 : Function { + override fun apply(data: HasDecimal64): Long { + return data.number.bits + } + } + + @Test + fun `test deserializing 32 bit decimal`() { + val protonJ = HasDecimal32(Decimal32(123456)) + val data = protonJ.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxProtonJ = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowDecimal32::class.java).newInstance(), + sandboxProtonJ + ) ?: fail("Result cannot be null") + + assertEquals(protonJ.number.bits.toString(), result.toString()) + } + } + + class ShowDecimal32 : Function { + override fun apply(data: HasDecimal32): Int { + return data.number.bits + } + } + + @Test + fun `test deserializing symbol`() { + val protonJ = HasSymbol(Symbol.valueOf("-my-symbol-value-")) + val data = protonJ.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxProtonJ = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowSymbol::class.java).newInstance(), + sandboxProtonJ + ) ?: fail("Result cannot be null") + + assertEquals(protonJ.symbol.toString(), result.toString()) + assertEquals(SANDBOX_STRING, result::class.java.name) + } + } + + class ShowSymbol : Function { + override fun apply(data: HasSymbol): String { + return data.symbol.toString() + } + } +} + +@CordaSerializable +class HasUnsignedLong(val number: UnsignedLong) + +@CordaSerializable +class HasUnsignedInteger(val number: UnsignedInteger) + +@CordaSerializable +class HasUnsignedShort(val number: UnsignedShort) + +@CordaSerializable +class HasUnsignedByte(val number: UnsignedByte) + +@CordaSerializable +class HasDecimal32(val number: Decimal32) + +@CordaSerializable +class HasDecimal64(val number: Decimal64) + +@CordaSerializable +class HasDecimal128(val number: Decimal128) + +@CordaSerializable +class HasSymbol(val symbol: Symbol) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializePublicKeyTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializePublicKeyTest.kt new file mode 100644 index 0000000000..e6834d0a39 --- /dev/null +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializePublicKeyTest.kt @@ -0,0 +1,96 @@ +package net.corda.djvm.serialization + +import net.corda.core.crypto.CompositeKey +import net.corda.core.crypto.Crypto +import net.corda.core.crypto.SignatureScheme +import net.corda.core.internal.hash +import net.corda.core.serialization.CordaSerializable +import net.corda.core.serialization.internal._contextSerializationEnv +import net.corda.core.serialization.serialize +import net.corda.djvm.serialization.SandboxType.* +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.junit.jupiter.api.extension.ExtensionContext +import org.junit.jupiter.api.fail +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.Arguments +import org.junit.jupiter.params.provider.ArgumentsProvider +import org.junit.jupiter.params.provider.ArgumentsSource +import java.security.PublicKey +import java.util.function.Function +import java.util.stream.Stream + +@ExtendWith(LocalSerialization::class) +class DeserializePublicKeyTest : TestBase(KOTLIN) { + class SignatureSchemeProvider : ArgumentsProvider { + override fun provideArguments(context: ExtensionContext?): Stream { + return Crypto.supportedSignatureSchemes().stream() + .filter { it != Crypto.COMPOSITE_KEY } + .map { Arguments.of(it) } + } + } + + @ArgumentsSource(SignatureSchemeProvider::class) + @ParameterizedTest(name = "{index} => {0}") + fun `test deserializing public key`(signatureScheme: SignatureScheme) { + val keyPair = Crypto.generateKeyPair(signatureScheme) + val publicKey = PublicKeyData(keyPair.public) + val data = publicKey.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxKey = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowPublicKey::class.java).newInstance(), + sandboxKey + ) ?: fail("Result cannot be null") + + assertEquals(ShowPublicKey().apply(publicKey), result.toString()) + assertEquals(SANDBOX_STRING, result::class.java.name) + } + } + + @Test + fun `test composite public key`() { + val key1 = Crypto.generateKeyPair(Crypto.ECDSA_SECP256K1_SHA256).public + val key2 = Crypto.generateKeyPair(Crypto.ECDSA_SECP256R1_SHA256).public + val key3 = Crypto.generateKeyPair(Crypto.EDDSA_ED25519_SHA512).public + + val compositeKey = CompositeKey.Builder() + .addKey(key1, weight = 1) + .addKey(key2, weight = 1) + .addKey(key3, weight = 1) + .build(2) + val compositeData = PublicKeyData(compositeKey) + val data = compositeData.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxKey = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowPublicKey::class.java).newInstance(), + sandboxKey + ) ?: fail("Result cannot be null") + + assertEquals(ShowPublicKey().apply(compositeData), result.toString()) + } + } + + class ShowPublicKey : Function { + override fun apply(data: PublicKeyData): String { + return with(data) { + "PublicKey: algorithm='${key.algorithm}', format='${key.format}', hash=${key.hash}" + } + } + } +} + +@CordaSerializable +data class PublicKeyData(val key: PublicKey) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeStringBufferTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeStringBufferTest.kt new file mode 100644 index 0000000000..6ae12c8c66 --- /dev/null +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeStringBufferTest.kt @@ -0,0 +1,40 @@ +package net.corda.djvm.serialization + +import net.corda.core.serialization.internal._contextSerializationEnv +import net.corda.core.serialization.serialize +import net.corda.djvm.serialization.SandboxType.* +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.junit.jupiter.api.fail +import java.util.function.Function + +@ExtendWith(LocalSerialization::class) +class DeserializeStringBufferTest : TestBase(KOTLIN) { + @Test + fun `test deserializing string buffer`() { + val buffer = StringBuffer("Hello World!") + val data = buffer.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxBigInteger = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowStringBuffer::class.java).newInstance(), + sandboxBigInteger + ) ?: fail("Result cannot be null") + + assertEquals(ShowStringBuffer().apply(buffer), result.toString()) + assertEquals(SANDBOX_STRING, result::class.java.name) + } + } + + class ShowStringBuffer : Function { + override fun apply(buffer: StringBuffer): String { + return buffer.toString() + } + } +} diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeStringTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeStringTest.kt new file mode 100644 index 0000000000..860952a8ab --- /dev/null +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeStringTest.kt @@ -0,0 +1,75 @@ +package net.corda.djvm.serialization + +import net.corda.core.serialization.CordaSerializable +import net.corda.core.serialization.internal._contextSerializationEnv +import net.corda.core.serialization.serialize +import net.corda.djvm.serialization.SandboxType.* +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.junit.jupiter.api.fail +import java.util.function.Function + +@ExtendWith(LocalSerialization::class) +class DeserializeStringTest : TestBase(KOTLIN) { + @Test + fun `test deserializing string`() { + val stringMessage = StringMessage("Hello World!") + val data = stringMessage.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxString = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowStringMessage::class.java).newInstance(), + sandboxString + ) ?: fail("Result cannot be null") + + assertEquals(stringMessage.message, result.toString()) + assertEquals(SANDBOX_STRING, result::class.java.name) + } + } + + class ShowStringMessage : Function { + override fun apply(data: StringMessage): String { + return data.message + } + } + + @Test + fun `test deserializing string list of arrays`() { + val stringListArray = StringListOfArray(listOf( + arrayOf("Hello"), arrayOf("World"), arrayOf("!")) + ) + val data = stringListArray.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxListArray = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowStringListOfArray::class.java).newInstance(), + sandboxListArray + ) ?: fail("Result cannot be null") + + assertEquals(stringListArray.data.flatMap(Array::toList).joinToString(), result.toString()) + } + } + + class ShowStringListOfArray : Function { + override fun apply(obj: StringListOfArray): String { + return obj.data.flatMap(Array::toList).joinToString() + } + } +} + +@CordaSerializable +data class StringMessage(val message: String) + +@CordaSerializable +class StringListOfArray(val data: List>) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeYearMonthTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeYearMonthTest.kt new file mode 100644 index 0000000000..0369972dc6 --- /dev/null +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeYearMonthTest.kt @@ -0,0 +1,41 @@ +package net.corda.djvm.serialization + +import net.corda.core.serialization.internal._contextSerializationEnv +import net.corda.core.serialization.serialize +import net.corda.djvm.serialization.SandboxType.* +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.junit.jupiter.api.fail +import java.time.YearMonth +import java.util.function.Function + +@ExtendWith(LocalSerialization::class) +class DeserializeYearMonthTest : TestBase(KOTLIN) { + @Test + fun `test deserializing year-month`() { + val yearMonth = YearMonth.now() + val data = yearMonth.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxYearMonth = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowYearMonth::class.java).newInstance(), + sandboxYearMonth + ) ?: fail("Result cannot be null") + + assertEquals(yearMonth.toString(), result.toString()) + assertEquals(SANDBOX_STRING, result::class.java.name) + } + } + + class ShowYearMonth : Function { + override fun apply(yearMonth: YearMonth): String { + return yearMonth.toString() + } + } +} diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeYearTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeYearTest.kt new file mode 100644 index 0000000000..5056586636 --- /dev/null +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeYearTest.kt @@ -0,0 +1,41 @@ +package net.corda.djvm.serialization + +import net.corda.core.serialization.internal._contextSerializationEnv +import net.corda.core.serialization.serialize +import net.corda.djvm.serialization.SandboxType.* +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.junit.jupiter.api.fail +import java.time.Year +import java.util.function.Function + +@ExtendWith(LocalSerialization::class) +class DeserializeYearTest : TestBase(KOTLIN) { + @Test + fun `test deserializing year`() { + val year = Year.now() + val data = year.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxYear = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowYear::class.java).newInstance(), + sandboxYear + ) ?: fail("Result cannot be null") + + assertEquals(year.toString(), result.toString()) + assertEquals(SANDBOX_STRING, result::class.java.name) + } + } + + class ShowYear : Function { + override fun apply(year: Year): String { + return year.toString() + } + } +} diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeZoneIdTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeZoneIdTest.kt new file mode 100644 index 0000000000..27afdf6978 --- /dev/null +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeZoneIdTest.kt @@ -0,0 +1,53 @@ +package net.corda.djvm.serialization + +import net.corda.core.serialization.internal._contextSerializationEnv +import net.corda.core.serialization.serialize +import net.corda.djvm.serialization.SandboxType.* +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.extension.ExtendWith +import org.junit.jupiter.api.extension.ExtensionContext +import org.junit.jupiter.api.fail +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.Arguments +import org.junit.jupiter.params.provider.ArgumentsProvider +import org.junit.jupiter.params.provider.ArgumentsSource +import java.time.ZoneId +import java.util.function.Function +import java.util.stream.Stream + +@ExtendWith(LocalSerialization::class) +class DeserializeZoneIdTest : TestBase(KOTLIN) { + class ZoneIdProvider : ArgumentsProvider { + override fun provideArguments(context: ExtensionContext?): Stream { + return ZoneId.getAvailableZoneIds().stream() + .sorted().limit(10).map { Arguments.of(ZoneId.of(it)) } + } + } + + @ArgumentsSource(ZoneIdProvider::class) + @ParameterizedTest(name = "{index} => {0}") + fun `test deserializing zone id`(zoneId: ZoneId) { + val data = zoneId.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxZoneId = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowZoneId::class.java).newInstance(), + sandboxZoneId + ) ?: fail("Result cannot be null") + + assertEquals(zoneId.toString(), result.toString()) + assertEquals(SANDBOX_STRING, result::class.java.name) + } + } + + class ShowZoneId : Function { + override fun apply(zoneId: ZoneId): String { + return zoneId.toString() + } + } +} diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeZonedDateTimeTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeZonedDateTimeTest.kt new file mode 100644 index 0000000000..70a8f6b03b --- /dev/null +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeZonedDateTimeTest.kt @@ -0,0 +1,41 @@ +package net.corda.djvm.serialization + +import net.corda.core.serialization.internal._contextSerializationEnv +import net.corda.core.serialization.serialize +import net.corda.djvm.serialization.SandboxType.* +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.junit.jupiter.api.fail +import java.time.ZonedDateTime +import java.util.function.Function + +@ExtendWith(LocalSerialization::class) +class DeserializeZonedDateTimeTest : TestBase(KOTLIN) { + @Test + fun `test deserializing zoned date-time`() { + val dateTime = ZonedDateTime.now() + val data = dateTime.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxDateTime = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowZonedDateTime::class.java).newInstance(), + sandboxDateTime + ) ?: fail("Result cannot be null") + + assertEquals(dateTime.toString(), result.toString()) + assertEquals(SANDBOX_STRING, result::class.java.name) + } + } + + class ShowZonedDateTime : Function { + override fun apply(dateTime: ZonedDateTime): String { + return dateTime.toString() + } + } +} diff --git a/src/test/kotlin/net/corda/djvm/serialization/LocalSerialization.kt b/src/test/kotlin/net/corda/djvm/serialization/LocalSerialization.kt new file mode 100644 index 0000000000..9eac387abf --- /dev/null +++ b/src/test/kotlin/net/corda/djvm/serialization/LocalSerialization.kt @@ -0,0 +1,60 @@ +package net.corda.djvm.serialization + +import net.corda.core.serialization.SerializationContext +import net.corda.core.serialization.SerializationContext.UseCase +import net.corda.core.serialization.SerializationCustomSerializer +import net.corda.core.serialization.SerializationWhitelist +import net.corda.core.serialization.internal.SerializationEnvironment +import net.corda.core.serialization.internal._contextSerializationEnv +import net.corda.serialization.internal.* +import net.corda.serialization.internal.amqp.* +import org.junit.jupiter.api.extension.AfterEachCallback +import org.junit.jupiter.api.extension.BeforeEachCallback +import org.junit.jupiter.api.extension.ExtensionContext + +class LocalSerialization : BeforeEachCallback, AfterEachCallback { + private companion object { + private val AMQP_P2P_CONTEXT = SerializationContextImpl( + amqpMagic, + LocalSerialization::class.java.classLoader, + GlobalTransientClassWhiteList(BuiltInExceptionsWhitelist()), + emptyMap(), + true, + UseCase.P2P, + null + ) + } + + override fun beforeEach(context: ExtensionContext) { + _contextSerializationEnv.set(createTestSerializationEnv()) + } + + override fun afterEach(context: ExtensionContext) { + _contextSerializationEnv.set(null) + } + + private fun createTestSerializationEnv(): SerializationEnvironment { + val factory = SerializationFactoryImpl(mutableMapOf()).apply { + registerScheme(AMQPSerializationScheme(emptySet(), emptySet(), AccessOrderLinkedHashMap(128))) + } + return SerializationEnvironment.with(factory, AMQP_P2P_CONTEXT) + } + + private class AMQPSerializationScheme( + customSerializers: Set>, + serializationWhitelists: Set, + serializerFactoriesForContexts: AccessOrderLinkedHashMap + ) : AbstractAMQPSerializationScheme(customSerializers, serializationWhitelists, serializerFactoriesForContexts) { + override fun rpcServerSerializerFactory(context: SerializationContext): SerializerFactory { + throw UnsupportedOperationException() + } + + override fun rpcClientSerializerFactory(context: SerializationContext): SerializerFactory { + throw UnsupportedOperationException() + } + + override fun canDeserializeVersion(magic: CordaSerializationMagic, target: UseCase): Boolean { + return canDeserializeVersion(magic) && target == UseCase.P2P + } + } +} diff --git a/src/test/kotlin/net/corda/djvm/serialization/SafeDeserialisationTest.kt b/src/test/kotlin/net/corda/djvm/serialization/SafeDeserialisationTest.kt new file mode 100644 index 0000000000..cf7d9cd8be --- /dev/null +++ b/src/test/kotlin/net/corda/djvm/serialization/SafeDeserialisationTest.kt @@ -0,0 +1,89 @@ +package net.corda.djvm.serialization + +import net.corda.core.serialization.SerializedBytes +import net.corda.core.serialization.internal._contextSerializationEnv +import net.corda.core.serialization.serialize +import net.corda.djvm.serialization.SandboxType.* +import net.corda.serialization.internal.SectionId +import net.corda.serialization.internal.amqp.* +import org.apache.qpid.proton.codec.Data +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertThrows +import org.junit.jupiter.api.extension.ExtendWith +import org.junit.jupiter.api.fail +import java.io.ByteArrayOutputStream +import java.util.function.Function + +@ExtendWith(LocalSerialization::class) +class SafeDeserialisationTest : TestBase(KOTLIN) { + companion object { + const val MESSAGE = "Nothing to see here..." + const val NUMBER = 123.toShort() + } + + @Test + fun `test deserialising an evil class`() { + val context = (_contextSerializationEnv.get() ?: fail("No serialization environment!")).p2pContext + + val innocent = InnocentData(MESSAGE, NUMBER) + val innocentData = innocent.serialize() + val envelope = DeserializationInput.getEnvelope(innocentData, context.encodingWhitelist).apply { + val innocentType = schema.types[0] as CompositeType + (schema.types as MutableList)[0] = CompositeType( + name = innocentType.name.replace("Innocent", "VeryEvil"), + label = innocentType.label, + provides = innocentType.provides, + descriptor = innocentType.descriptor, + fields = innocentType.fields + ) + } + val evilData = SerializedBytes(envelope.write()) + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxData = evilData.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowInnocentData::class.java).newInstance(), + sandboxData + ) ?: fail("Result cannot be null") + + // Check that we have deserialised the data without instantiating the Evil class. + assertThat(result.toString()) + .isEqualTo("sandbox.net.corda.djvm.serialization.VeryEvilData: $MESSAGE, $NUMBER") + + // Check that instantiating the Evil class does indeed cause an error. + val ex = assertThrows{ VeryEvilData("Naughty!", 0) } + assertThat(ex.cause) + .isExactlyInstanceOf(IllegalStateException::class.java) + .hasMessageContaining("Victory is mine!") + } + } + + private fun Envelope.write(): ByteArray { + val data = Data.Factory.create() + data.withDescribed(Envelope.DESCRIPTOR_OBJECT) { + withList { + putObject(obj) + putObject(schema) + putObject(transformsSchema) + } + } + return ByteArrayOutputStream().use { + amqpMagic.writeTo(it) + SectionId.DATA_AND_STOP.writeTo(it) + it.alsoAsByteBuffer(data.encodedSize().toInt(), data::encode) + it.toByteArray() + } + } + + class ShowInnocentData : Function { + override fun apply(data: InnocentData): String { + return "${data::class.java.name}: ${data.message}, ${data.number}" + } + } +} + diff --git a/src/test/kotlin/net/corda/djvm/serialization/SandboxType.kt b/src/test/kotlin/net/corda/djvm/serialization/SandboxType.kt new file mode 100644 index 0000000000..03d07affc6 --- /dev/null +++ b/src/test/kotlin/net/corda/djvm/serialization/SandboxType.kt @@ -0,0 +1,6 @@ +package net.corda.djvm.serialization + +enum class SandboxType { + JAVA, + KOTLIN +} diff --git a/src/test/kotlin/net/corda/djvm/serialization/TestBase.kt b/src/test/kotlin/net/corda/djvm/serialization/TestBase.kt new file mode 100644 index 0000000000..0a178a5575 --- /dev/null +++ b/src/test/kotlin/net/corda/djvm/serialization/TestBase.kt @@ -0,0 +1,139 @@ +package net.corda.djvm.serialization + +import net.corda.core.serialization.ConstructorForDeserialization +import net.corda.core.serialization.CordaSerializable +import net.corda.djvm.SandboxConfiguration +import net.corda.djvm.SandboxConfiguration.Companion.ALL_DEFINITION_PROVIDERS +import net.corda.djvm.SandboxConfiguration.Companion.ALL_EMITTERS +import net.corda.djvm.SandboxConfiguration.Companion.ALL_RULES +import net.corda.djvm.SandboxRuntimeContext +import net.corda.djvm.analysis.AnalysisConfiguration +import net.corda.djvm.analysis.Whitelist.Companion.MINIMAL +import net.corda.djvm.execution.ExecutionProfile.* +import net.corda.djvm.execution.SandboxRuntimeException +import net.corda.djvm.messages.Severity +import net.corda.djvm.messages.Severity.* +import net.corda.djvm.rewiring.SandboxClassLoader +import net.corda.djvm.source.BootstrapClassLoader +import net.corda.djvm.source.UserPathSource +import org.junit.jupiter.api.AfterAll +import org.junit.jupiter.api.BeforeAll +import org.junit.jupiter.api.fail +import java.io.File +import java.lang.reflect.InvocationTargetException +import java.nio.file.Files.exists +import java.nio.file.Files.isDirectory +import java.nio.file.Path +import java.nio.file.Paths +import java.util.function.BiFunction +import kotlin.concurrent.thread + +@Suppress("unused", "MemberVisibilityCanBePrivate") +abstract class TestBase(type: SandboxType) { + companion object { + const val SANDBOX_STRING = "sandbox.java.lang.String" + + @JvmField + val DETERMINISTIC_RT: Path = Paths.get( + System.getProperty("deterministic-rt.path") ?: fail("deterministic-rt.path property not set")) + + @JvmField + val TESTING_LIBRARIES: List = (System.getProperty("sandbox-libraries.path") ?: fail("sandbox-libraries.path property not set")) + .split(File.pathSeparator).map { Paths.get(it) }.filter { exists(it) } + + private lateinit var configuration: SandboxConfiguration + private lateinit var classLoader: SandboxClassLoader + + @BeforeAll + @JvmStatic + fun setupClassLoader() { + val rootConfiguration = AnalysisConfiguration.createRoot( + userSource = UserPathSource(emptyList()), + whitelist = MINIMAL, + visibleAnnotations = setOf( + CordaSerializable::class.java, + ConstructorForDeserialization::class.java + ), + bootstrapSource = BootstrapClassLoader(DETERMINISTIC_RT) + ) + configuration = SandboxConfiguration.of( + UNLIMITED, + ALL_RULES, + ALL_EMITTERS, + ALL_DEFINITION_PROVIDERS, + true, + rootConfiguration + ) + classLoader = SandboxClassLoader.createFor(configuration) + } + + @AfterAll + @JvmStatic + fun destroyRootContext() { + configuration.analysisConfiguration.closeAll() + } + } + + val classPaths: List = when(type) { + SandboxType.KOTLIN -> TESTING_LIBRARIES + SandboxType.JAVA -> TESTING_LIBRARIES.filter { isDirectory(it) } + } + + fun sandbox(action: SandboxRuntimeContext.() -> Unit) { + return sandbox(WARNING, emptySet(), false, action) + } + + fun sandbox(visibleAnnotations: Set>, action: SandboxRuntimeContext.() -> Unit) { + return sandbox(WARNING, visibleAnnotations, false, action) + } + + fun sandbox( + minimumSeverityLevel: Severity, + visibleAnnotations: Set>, + enableTracing: Boolean, + action: SandboxRuntimeContext.() -> Unit + ) { + var thrownException: Throwable? = null + thread { + try { + configuration.analysisConfiguration.createChild( + userSource = UserPathSource(classPaths), + newMinimumSeverityLevel = minimumSeverityLevel, + visibleAnnotations = visibleAnnotations + ).use { analysisConfiguration -> + SandboxRuntimeContext(SandboxConfiguration.of( + configuration.executionProfile, + configuration.rules, + configuration.emitters, + configuration.definitionProviders, + enableTracing, + analysisConfiguration, + classLoader + )).use { + action(this) + } + } + } catch (exception: Throwable) { + thrownException = exception + } + }.join() + throw thrownException ?: return + } + + fun createExecutorFor(classLoader: SandboxClassLoader): BiFunction { + val taskClass = classLoader.loadClass("sandbox.RawTask") + val taskApply = taskClass.getDeclaredMethod("apply", Any::class.java) + val taskConstructor = taskClass.getDeclaredConstructor(classLoader.loadClass("sandbox.java.util.function.Function")) + return BiFunction { userTask, arg -> + try { + taskApply(taskConstructor.newInstance(userTask), arg) + } catch (ex: InvocationTargetException) { + val target = ex.targetException + throw when (target) { + is RuntimeException, is Error -> target + else -> SandboxRuntimeException(target.message, target) + } + } + } + } +} \ No newline at end of file diff --git a/src/test/resources/log4j2-test.xml b/src/test/resources/log4j2-test.xml new file mode 100644 index 0000000000..cf527ff319 --- /dev/null +++ b/src/test/resources/log4j2-test.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/testing.cert b/src/test/resources/testing.cert new file mode 100644 index 0000000000000000000000000000000000000000..03e1558cca71d9fe0f42f4a11d7d3cb1e8819cd8 GIT binary patch literal 801 zcmXqLVwN>%Vq#su%*4pV#G)>I_M8DP8>d#AN85K^Mn-N{1_OITZUas>=1>+kVWv=T zLw=wh-iR;`|A7Okpt!?a9szwH60GhChPCi~uf^2S8=)n@;7YDZZm z{c?HIi*mL;3p&xdb%n7&yWGT-uE3kiHhHnx$C$mkYB5J=xANThDRbY3Y@ONObK;-d zf!W>jfrP9~=8sSP>s9$LH1{%BR7na$#{4b*2X7op zy;0KdEmTsR<5s2EUASxWv51K9@0ynVaP#Y&tEQrsnq5(M+Y{y?2O==$fq}@#Fsu3Rv3X(Y z=N)U>Z?=|gTKi@}*0bsMFTCQCG9FmeRLNbF$^E16@U?rY?v?JfK92lek#pY_RvNkg zo_g|%rTNY8evgc2W^OK3e(w@?t1Pm0=#fz14mkCUrW8!_Qt2W5@^I?CdwYGJV zZg$&}_m-cKK7F%+Vee^&-)<8-ME9_Bzwg*}`2bf(v!j@#USn{`pOtR|*0edEdhSxa zy7X3sd)}K-q$d^;=-W+n_{!*Ds G*+&5lOg@qT literal 0 HcmV?d00001 diff --git a/src/test/scripts/generate-certificate.sh b/src/test/scripts/generate-certificate.sh new file mode 100755 index 0000000000..4863542cd5 --- /dev/null +++ b/src/test/scripts/generate-certificate.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +KEYPASS=deterministic +STOREPASS=deterministic + +rm -f keystore testing.cert + +keytool -keystore keystore -storetype pkcs12 -genkey -dname 'CN=localhost, O=R3, L=London, C=UK' -keyalg RSA -validity 3650 -keypass ${KEYPASS} -storepass ${STOREPASS} +keytool -keystore keystore -storetype pkcs12 -export -keyalg RSA -file testing.cert -keypass ${KEYPASS} -storepass ${STOREPASS} + +rm -f keystore From f68c4b3308c719aee77ad8f95bc58e999750e13e Mon Sep 17 00:00:00 2001 From: Chris Rankin Date: Tue, 3 Sep 2019 11:35:48 +0100 Subject: [PATCH 02/18] CORDA-3174: Extend serialisation to include InputStream and OpaqueBytesSubSequence. (#60) * Update DJVM Example project for serialisation. * Add serializers for InputStream and OpaqueBytesSubSequence. * Support ZIP Inflater and CRC32 inside the sandbox. * Allow the DJVM to wrap java.io.InputStream as sandbox.java.io.InputStream. * Configure tests also to preserve @DeprecatedConstructorForDeserialization. --- build.gradle | 4 +- .../deserializers/InputStreamDeserializer.kt | 11 ++++ .../OpaqueBytesSubSequenceDeserializer.kt | 11 ++++ .../serialization/AMQPSerializationScheme.kt | 2 + .../corda/djvm/serialization/Serialization.kt | 5 +- .../SandboxInputStreamSerializer.kt | 40 +++++++++++++++ ...SandboxOpaqueBytesSubSequenceSerializer.kt | 31 ++++++++++++ .../DeserializeInputStreamTest.kt | 45 +++++++++++++++++ .../DeserializeOpaqueBytesSubSequenceTest.kt | 50 +++++++++++++++++++ .../net/corda/djvm/serialization/TestBase.kt | 4 +- 10 files changed, 198 insertions(+), 5 deletions(-) create mode 100644 deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/InputStreamDeserializer.kt create mode 100644 deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/OpaqueBytesSubSequenceDeserializer.kt create mode 100644 src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxInputStreamSerializer.kt create mode 100644 src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOpaqueBytesSubSequenceSerializer.kt create mode 100644 src/test/kotlin/net/corda/djvm/serialization/DeserializeInputStreamTest.kt create mode 100644 src/test/kotlin/net/corda/djvm/serialization/DeserializeOpaqueBytesSubSequenceTest.kt diff --git a/build.gradle b/build.gradle index 30395c53f3..6fbcc81d9c 100644 --- a/build.gradle +++ b/build.gradle @@ -33,8 +33,8 @@ allprojects { cacheChangingModulesFor 0, 'seconds' dependencySubstitution { - substitute module("net.corda:corda-core:$corda_version") with module("net.corda:corda-core-deterministic:$corda_version") - substitute module("net.corda:corda-serialization:$corda_version") with module("net.corda:corda-serialization-deterministic:$corda_version") + substitute module("net.corda:corda-core") with module("net.corda:corda-core-deterministic:$corda_version") + substitute module("net.corda:corda-serialization") with module("net.corda:corda-serialization-deterministic:$corda_version") } } } diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/InputStreamDeserializer.kt b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/InputStreamDeserializer.kt new file mode 100644 index 0000000000..98938615ec --- /dev/null +++ b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/InputStreamDeserializer.kt @@ -0,0 +1,11 @@ +package net.corda.djvm.serialization.deserializers + +import java.io.ByteArrayInputStream +import java.io.InputStream +import java.util.function.Function + +class InputStreamDeserializer : Function { + override fun apply(bytes: ByteArray): InputStream? { + return ByteArrayInputStream(bytes) + } +} diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/OpaqueBytesSubSequenceDeserializer.kt b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/OpaqueBytesSubSequenceDeserializer.kt new file mode 100644 index 0000000000..21423b9720 --- /dev/null +++ b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/OpaqueBytesSubSequenceDeserializer.kt @@ -0,0 +1,11 @@ +package net.corda.djvm.serialization.deserializers + +import net.corda.core.utilities.OpaqueBytes +import net.corda.core.utilities.OpaqueBytesSubSequence +import java.util.function.Function + +class OpaqueBytesSubSequenceDeserializer : Function { + override fun apply(proxy: OpaqueBytes): OpaqueBytesSubSequence { + return OpaqueBytesSubSequence(proxy.bytes, proxy.offset, proxy.size) + } +} diff --git a/src/main/kotlin/net/corda/djvm/serialization/AMQPSerializationScheme.kt b/src/main/kotlin/net/corda/djvm/serialization/AMQPSerializationScheme.kt index 90981d486a..348ae98f24 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/AMQPSerializationScheme.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/AMQPSerializationScheme.kt @@ -28,6 +28,7 @@ class AMQPSerializationScheme( register(SandboxCertPathSerializer(classLoader, executor, this)) register(SandboxDurationSerializer(classLoader, executor, this)) register(SandboxEnumSetSerializer(classLoader, executor, this)) + register(SandboxInputStreamSerializer(classLoader, executor)) register(SandboxInstantSerializer(classLoader, executor, this)) register(SandboxLocalDateSerializer(classLoader, executor, this)) register(SandboxLocalDateTimeSerializer(classLoader, executor, this)) @@ -40,6 +41,7 @@ class AMQPSerializationScheme( register(SandboxYearSerializer(classLoader, executor, this)) register(SandboxZonedDateTimeSerializer(classLoader, executor, this)) register(SandboxZoneIdSerializer(classLoader, executor, this)) + register(SandboxOpaqueBytesSubSequenceSerializer(classLoader, executor, this)) register(SandboxOptionalSerializer(classLoader, executor, this)) register(SandboxPrimitiveSerializer(UUID::class.java, classLoader, sandboxBasicInput)) register(SandboxPrimitiveSerializer(String::class.java, classLoader, sandboxBasicInput)) diff --git a/src/main/kotlin/net/corda/djvm/serialization/Serialization.kt b/src/main/kotlin/net/corda/djvm/serialization/Serialization.kt index 8e1f16d4a4..f774fe9bdd 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/Serialization.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/Serialization.kt @@ -6,6 +6,7 @@ import net.corda.core.serialization.SerializationContext.UseCase import net.corda.core.serialization.SerializationFactory import net.corda.core.serialization.SerializedBytes import net.corda.core.serialization.internal.SerializationEnvironment +import net.corda.core.utilities.ByteSequence import net.corda.djvm.execution.SandboxRuntimeException import net.corda.djvm.rewiring.SandboxClassLoader import net.corda.djvm.serialization.serializers.PrimitiveSerializer @@ -73,11 +74,11 @@ inline fun SerializedBytes.deserializeFor(classLoader: Sand return deserializeTo(clazz, classLoader) } -fun SerializedBytes<*>.deserializeTo(clazz: Class<*>, classLoader: SandboxClassLoader): Any { +fun ByteSequence.deserializeTo(clazz: Class<*>, classLoader: SandboxClassLoader): Any { return deserializeTo(clazz, classLoader, SerializationFactory.defaultFactory) } -fun SerializedBytes<*>.deserializeTo(clazz: Class<*>, classLoader: SandboxClassLoader, factory: SerializationFactory): Any { +fun ByteSequence.deserializeTo(clazz: Class<*>, classLoader: SandboxClassLoader, factory: SerializationFactory): Any { val obj = factory.deserialize(this, Any::class.java, factory.defaultContext) return if (clazz.isInstance(obj)) { obj diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxInputStreamSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxInputStreamSerializer.kt new file mode 100644 index 0000000000..c7b6465072 --- /dev/null +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxInputStreamSerializer.kt @@ -0,0 +1,40 @@ +package net.corda.djvm.serialization.serializers + +import net.corda.core.serialization.SerializationContext +import net.corda.djvm.rewiring.SandboxClassLoader +import net.corda.djvm.serialization.deserializers.InputStreamDeserializer +import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.serialization.internal.amqp.* +import org.apache.qpid.proton.codec.Data +import java.io.InputStream +import java.lang.reflect.Type +import java.util.Collections.singleton +import java.util.function.BiFunction +import java.util.function.Function + +class SandboxInputStreamSerializer( + classLoader: SandboxClassLoader, + executor: BiFunction +) : CustomSerializer.Implements(classLoader.loadClassForSandbox(InputStream::class.java)) { + private val decoder: Function + + init { + val decodeTask = classLoader.loadClassForSandbox(InputStreamDeserializer::class.java).newInstance() + decoder = Function { inputs -> + executor.apply(decodeTask, inputs) + } + } + + override val schemaForDocumentation: Schema = Schema(emptyList()) + + override val deserializationAliases: Set> = singleton(InputStream::class.java) + + override fun readObject(obj: Any, schemas: SerializationSchemas, input: DeserializationInput, context: SerializationContext): Any { + val bits = input.readObject(obj, schemas, ByteArray::class.java, context) as ByteArray + return decoder.apply(bits)!! + } + + override fun writeDescribedObject(obj: Any, data: Data, type: Type, output: SerializationOutput, context: SerializationContext) { + abortReadOnly() + } +} diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOpaqueBytesSubSequenceSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOpaqueBytesSubSequenceSerializer.kt new file mode 100644 index 0000000000..7d41b81930 --- /dev/null +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOpaqueBytesSubSequenceSerializer.kt @@ -0,0 +1,31 @@ +package net.corda.djvm.serialization.serializers + +import net.corda.core.utilities.OpaqueBytes +import net.corda.core.utilities.OpaqueBytesSubSequence +import net.corda.djvm.rewiring.SandboxClassLoader +import net.corda.djvm.serialization.deserializers.OpaqueBytesSubSequenceDeserializer +import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.serialization.internal.amqp.CustomSerializer +import net.corda.serialization.internal.amqp.SerializerFactory +import java.util.Collections.singleton +import java.util.function.BiFunction + +class SandboxOpaqueBytesSubSequenceSerializer( + classLoader: SandboxClassLoader, + private val executor: BiFunction, + factory: SerializerFactory +) : CustomSerializer.Proxy( + clazz = classLoader.loadClassForSandbox(OpaqueBytesSubSequence::class.java), + proxyClass = classLoader.loadClassForSandbox(OpaqueBytes::class.java), + factory = factory +) { + private val task = classLoader.loadClassForSandbox(OpaqueBytesSubSequenceDeserializer::class.java).newInstance() + + override val deserializationAliases: Set> = singleton(OpaqueBytesSubSequence::class.java) + + override fun toProxy(obj: Any): Any = abortReadOnly() + + override fun fromProxy(proxy: Any): Any { + return executor.apply(task, proxy)!! + } +} diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeInputStreamTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeInputStreamTest.kt new file mode 100644 index 0000000000..84cdd80712 --- /dev/null +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeInputStreamTest.kt @@ -0,0 +1,45 @@ +package net.corda.djvm.serialization + +import net.corda.core.internal.readFully +import net.corda.core.serialization.internal._contextSerializationEnv +import net.corda.core.serialization.serialize +import net.corda.djvm.serialization.SandboxType.* +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.junit.jupiter.api.fail +import java.io.InputStream +import java.util.function.Function + +@ExtendWith(LocalSerialization::class) +class DeserializeInputStreamTest : TestBase(KOTLIN) { + companion object { + const val MESSAGE = "Round and round the rugged rocks..." + } + + @Test + fun `test deserializing input stream`() { + val data = MESSAGE.byteInputStream().serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxStream = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowInputStream::class.java).newInstance(), + sandboxStream + ) ?: fail("Result cannot be null") + + assertEquals(String(MESSAGE.byteInputStream().readFully()), result.toString()) + assertEquals(SANDBOX_STRING, result::class.java.name) + } + } + + class ShowInputStream : Function { + override fun apply(input: InputStream): String { + return String(input.readFully()) + } + } +} diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeOpaqueBytesSubSequenceTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeOpaqueBytesSubSequenceTest.kt new file mode 100644 index 0000000000..519a86e6e3 --- /dev/null +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeOpaqueBytesSubSequenceTest.kt @@ -0,0 +1,50 @@ +package net.corda.djvm.serialization + +import net.corda.core.serialization.internal._contextSerializationEnv +import net.corda.core.serialization.serialize +import net.corda.core.utilities.OpaqueBytesSubSequence +import net.corda.djvm.serialization.SandboxType.* +import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.junit.jupiter.api.fail +import java.util.function.Function + +@ExtendWith(LocalSerialization::class) +class DeserializeOpaqueBytesSubSequenceTest : TestBase(KOTLIN) { + companion object { + const val MESSAGE = "The rain in spain falls mainly on the plain." + const val OFFSET = MESSAGE.length / 2 + } + + @Test + fun `test deserializing opaquebytes subsequence`() { + val subSequence = OpaqueBytesSubSequence( + bytes = MESSAGE.toByteArray(), + offset = OFFSET, + size = MESSAGE.length - OFFSET + ) + val data = subSequence.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxBytes = data.deserializeFor(classLoader) + + val executor = createExecutorFor(classLoader) + val result = executor.apply( + classLoader.loadClassForSandbox(ShowOpaqueBytesSubSequence::class.java).newInstance(), + sandboxBytes + ) ?: fail("Result cannot be null") + + assertEquals(MESSAGE.substring(OFFSET), String(result as ByteArray)) + assertEquals(String(subSequence.copyBytes()), String(result)) + } + } + + class ShowOpaqueBytesSubSequence : Function { + override fun apply(sequence: OpaqueBytesSubSequence): ByteArray { + return sequence.copyBytes() + } + } +} diff --git a/src/test/kotlin/net/corda/djvm/serialization/TestBase.kt b/src/test/kotlin/net/corda/djvm/serialization/TestBase.kt index 0a178a5575..29af995f0f 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/TestBase.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/TestBase.kt @@ -2,6 +2,7 @@ package net.corda.djvm.serialization import net.corda.core.serialization.ConstructorForDeserialization import net.corda.core.serialization.CordaSerializable +import net.corda.core.serialization.DeprecatedConstructorForDeserialization import net.corda.djvm.SandboxConfiguration import net.corda.djvm.SandboxConfiguration.Companion.ALL_DEFINITION_PROVIDERS import net.corda.djvm.SandboxConfiguration.Companion.ALL_EMITTERS @@ -52,7 +53,8 @@ abstract class TestBase(type: SandboxType) { whitelist = MINIMAL, visibleAnnotations = setOf( CordaSerializable::class.java, - ConstructorForDeserialization::class.java + ConstructorForDeserialization::class.java, + DeprecatedConstructorForDeserialization::class.java ), bootstrapSource = BootstrapClassLoader(DETERMINISTIC_RT) ) From 7a6c18156c27d72e98eef85e6ee1cd46a5e4af00 Mon Sep 17 00:00:00 2001 From: Chris Rankin Date: Mon, 9 Sep 2019 18:14:33 +0100 Subject: [PATCH 03/18] CORDA-2871: Sanity fixes! (#63) * Improve message for SandboxClassLoadingException. * Fix serialisation API for using sandboxed environment. --- .../net/corda/djvm/serialization/Serialization.kt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/net/corda/djvm/serialization/Serialization.kt b/src/main/kotlin/net/corda/djvm/serialization/Serialization.kt index f774fe9bdd..bd15c6da6c 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/Serialization.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/Serialization.kt @@ -75,11 +75,17 @@ inline fun SerializedBytes.deserializeFor(classLoader: Sand } fun ByteSequence.deserializeTo(clazz: Class<*>, classLoader: SandboxClassLoader): Any { - return deserializeTo(clazz, classLoader, SerializationFactory.defaultFactory) + val factory = SerializationFactory.defaultFactory + return deserializeTo(clazz, classLoader, factory, factory.defaultContext) } -fun ByteSequence.deserializeTo(clazz: Class<*>, classLoader: SandboxClassLoader, factory: SerializationFactory): Any { - val obj = factory.deserialize(this, Any::class.java, factory.defaultContext) +fun ByteSequence.deserializeTo( + clazz: Class<*>, + classLoader: SandboxClassLoader, + factory: SerializationFactory, + context: SerializationContext +): Any { + val obj = factory.deserialize(this, Any::class.java, context) return if (clazz.isInstance(obj)) { obj } else { From 062acf89beee984f93c19a7de8ba808a8b8b2e2a Mon Sep 17 00:00:00 2001 From: Chris Rankin Date: Tue, 10 Sep 2019 10:55:55 +0100 Subject: [PATCH 04/18] CORDA-2871: Modify sandbox tasks to implement both java.Function and sandbox.Function (#62) * Modify sandbox tasks to implement both java.Function and sandbox.Function. * Make TaskExecutors implement BiFunction to make them composable. * Create ImportTask to wrap a java.Function inside a sandbox.Function. * Add createExecutor() and createRawExecutor() APIs to SandboxClassLoader. * Update serialization to use SandboxClassLoader.toSandboxClass(). * Remove a layer of lambdas from the serialisation code. * Update SandboxExecutor and SandboxRawExecutor. * Rename Executor to TaskFactory. * Rename dangling executor -> taskFactory. --- .../serialization/AMQPSerializationScheme.kt | 77 +++++++++--------- .../corda/djvm/serialization/Serialization.kt | 29 ++----- .../serializers/SandboxBitSetSerializer.kt | 14 ++-- .../serializers/SandboxCertPathSerializer.kt | 14 ++-- .../serializers/SandboxCharacterSerializer.kt | 4 +- .../serializers/SandboxClassSerializer.kt | 19 ++--- .../SandboxCollectionSerializer.kt | 20 ++--- .../serializers/SandboxCurrencySerializer.kt | 16 ++-- .../SandboxDecimal128Serializer.kt | 16 ++-- .../serializers/SandboxDecimal32Serializer.kt | 16 ++-- .../serializers/SandboxDecimal64Serializer.kt | 16 ++-- .../serializers/SandboxDurationSerializer.kt | 14 ++-- .../serializers/SandboxEnumSerializer.kt | 17 ++-- .../serializers/SandboxEnumSetSerializer.kt | 16 ++-- .../SandboxInputStreamSerializer.kt | 16 ++-- .../serializers/SandboxInstantSerializer.kt | 14 ++-- .../serializers/SandboxLocalDateSerializer.kt | 14 ++-- .../SandboxLocalDateTimeSerializer.kt | 14 ++-- .../serializers/SandboxLocalTimeSerializer.kt | 14 ++-- .../serializers/SandboxMapSerializer.kt | 18 ++--- .../serializers/SandboxMonthDaySerializer.kt | 14 ++-- .../SandboxOffsetDateTimeSerializer.kt | 14 ++-- .../SandboxOffsetTimeSerializer.kt | 14 ++-- ...SandboxOpaqueBytesSubSequenceSerializer.kt | 14 ++-- .../serializers/SandboxOptionalSerializer.kt | 14 ++-- .../serializers/SandboxPeriodSerializer.kt | 14 ++-- .../serializers/SandboxPrimitiveSerializer.kt | 4 +- .../serializers/SandboxPublicKeySerializer.kt | 16 ++-- .../serializers/SandboxSymbolSerializer.kt | 13 ++- .../serializers/SandboxToStringSerializer.kt | 13 ++- .../SandboxUnsignedByteSerializer.kt | 16 ++-- .../SandboxUnsignedIntegerSerializer.kt | 16 ++-- .../SandboxUnsignedLongSerializer.kt | 17 ++-- .../SandboxUnsignedShortSerializer.kt | 16 ++-- .../serializers/SandboxX509CRLSerializer.kt | 16 ++-- .../SandboxX509CertificateSerializer.kt | 16 ++-- .../serializers/SandboxYearMonthSerializer.kt | 14 ++-- .../serializers/SandboxYearSerializer.kt | 14 ++-- .../serializers/SandboxZoneIdSerializer.kt | 14 ++-- .../SandboxZonedDateTimeSerializer.kt | 24 +++--- .../DeserializeBigDecimalTest.kt | 8 +- .../DeserializeBigIntegerTest.kt | 8 +- .../serialization/DeserializeBitSetTest.kt | 8 +- .../DeserializeCertificatesTest.kt | 24 +++--- .../serialization/DeserializeClassTest.kt | 8 +- .../DeserializeCollectionsTest.kt | 56 +++++-------- .../serialization/DeserializeCurrencyTest.kt | 8 +- .../serialization/DeserializeEnumSetTest.kt | 8 +- .../djvm/serialization/DeserializeEnumTest.kt | 8 +- .../serialization/DeserializeGenericsTest.kt | 16 ++-- .../DeserializeInputStreamTest.kt | 8 +- .../serialization/DeserializeInstantTest.kt | 8 +- ...rializeJavaWithMultipleConstructorsTest.kt | 8 +- .../serialization/DeserializeLocalDateTest.kt | 8 +- .../DeserializeLocalDateTimeTest.kt | 8 +- .../serialization/DeserializeLocalTimeTest.kt | 8 +- .../djvm/serialization/DeserializeMapsTest.kt | 48 +++++------ .../serialization/DeserializeMonthDayTest.kt | 8 +- .../DeserializeObjectArraysTest.kt | 80 +++++++------------ .../DeserializeOffsetDateTimeTest.kt | 8 +- .../DeserializeOffsetTimeTest.kt | 8 +- .../DeserializeOpaqueBytesSubSequenceTest.kt | 8 +- .../serialization/DeserializeOptionalTest.kt | 16 ++-- .../serialization/DeserializePeriodTest.kt | 8 +- .../DeserializePrimitiveArraysTest.kt | 64 ++++++--------- .../serialization/DeserializeProtonJTest.kt | 64 ++++++--------- .../serialization/DeserializePublicKeyTest.kt | 16 ++-- .../DeserializeStringBufferTest.kt | 10 +-- .../serialization/DeserializeStringTest.kt | 16 ++-- .../serialization/DeserializeYearMonthTest.kt | 8 +- .../djvm/serialization/DeserializeYearTest.kt | 8 +- .../serialization/DeserializeZoneIdTest.kt | 8 +- .../DeserializeZonedDateTimeTest.kt | 8 +- .../serialization/SafeDeserialisationTest.kt | 8 +- .../net/corda/djvm/serialization/TestBase.kt | 22 +---- 75 files changed, 500 insertions(+), 787 deletions(-) diff --git a/src/main/kotlin/net/corda/djvm/serialization/AMQPSerializationScheme.kt b/src/main/kotlin/net/corda/djvm/serialization/AMQPSerializationScheme.kt index 348ae98f24..174cb301fc 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/AMQPSerializationScheme.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/AMQPSerializationScheme.kt @@ -12,37 +12,36 @@ import net.corda.serialization.internal.amqp.* import java.math.BigDecimal import java.math.BigInteger import java.util.* -import java.util.function.BiFunction import java.util.function.Function class AMQPSerializationScheme( private val classLoader: SandboxClassLoader, private val sandboxBasicInput: Function, - private val executor: BiFunction, + private val taskFactory: Function>, private val serializerFactoryFactory: SerializerFactoryFactory ) : SerializationScheme { private fun getSerializerFactory(context: SerializationContext): SerializerFactory { return serializerFactoryFactory.make(context).apply { - register(SandboxBitSetSerializer(classLoader, executor, this)) - register(SandboxCertPathSerializer(classLoader, executor, this)) - register(SandboxDurationSerializer(classLoader, executor, this)) - register(SandboxEnumSetSerializer(classLoader, executor, this)) - register(SandboxInputStreamSerializer(classLoader, executor)) - register(SandboxInstantSerializer(classLoader, executor, this)) - register(SandboxLocalDateSerializer(classLoader, executor, this)) - register(SandboxLocalDateTimeSerializer(classLoader, executor, this)) - register(SandboxLocalTimeSerializer(classLoader, executor, this)) - register(SandboxMonthDaySerializer(classLoader, executor, this)) - register(SandboxOffsetDateTimeSerializer(classLoader, executor, this)) - register(SandboxOffsetTimeSerializer(classLoader, executor, this)) - register(SandboxPeriodSerializer(classLoader, executor, this)) - register(SandboxYearMonthSerializer(classLoader, executor, this)) - register(SandboxYearSerializer(classLoader, executor, this)) - register(SandboxZonedDateTimeSerializer(classLoader, executor, this)) - register(SandboxZoneIdSerializer(classLoader, executor, this)) - register(SandboxOpaqueBytesSubSequenceSerializer(classLoader, executor, this)) - register(SandboxOptionalSerializer(classLoader, executor, this)) + register(SandboxBitSetSerializer(classLoader, taskFactory, this)) + register(SandboxCertPathSerializer(classLoader, taskFactory, this)) + register(SandboxDurationSerializer(classLoader, taskFactory, this)) + register(SandboxEnumSetSerializer(classLoader, taskFactory, this)) + register(SandboxInputStreamSerializer(classLoader, taskFactory)) + register(SandboxInstantSerializer(classLoader, taskFactory, this)) + register(SandboxLocalDateSerializer(classLoader, taskFactory, this)) + register(SandboxLocalDateTimeSerializer(classLoader, taskFactory, this)) + register(SandboxLocalTimeSerializer(classLoader, taskFactory, this)) + register(SandboxMonthDaySerializer(classLoader, taskFactory, this)) + register(SandboxOffsetDateTimeSerializer(classLoader, taskFactory, this)) + register(SandboxOffsetTimeSerializer(classLoader, taskFactory, this)) + register(SandboxPeriodSerializer(classLoader, taskFactory, this)) + register(SandboxYearMonthSerializer(classLoader, taskFactory, this)) + register(SandboxYearSerializer(classLoader, taskFactory, this)) + register(SandboxZonedDateTimeSerializer(classLoader, taskFactory, this)) + register(SandboxZoneIdSerializer(classLoader, taskFactory, this)) + register(SandboxOpaqueBytesSubSequenceSerializer(classLoader, taskFactory, this)) + register(SandboxOptionalSerializer(classLoader, taskFactory, this)) register(SandboxPrimitiveSerializer(UUID::class.java, classLoader, sandboxBasicInput)) register(SandboxPrimitiveSerializer(String::class.java, classLoader, sandboxBasicInput)) register(SandboxPrimitiveSerializer(Byte::class.javaObjectType, classLoader, sandboxBasicInput)) @@ -54,24 +53,24 @@ class AMQPSerializationScheme( register(SandboxPrimitiveSerializer(Boolean::class.javaObjectType, classLoader, sandboxBasicInput)) register(SandboxPrimitiveSerializer(Date::class.javaObjectType, classLoader, sandboxBasicInput)) register(SandboxCharacterSerializer(classLoader, sandboxBasicInput)) - register(SandboxCollectionSerializer(classLoader, executor, this)) - register(SandboxMapSerializer(classLoader, executor, this)) - register(SandboxEnumSerializer(classLoader, executor, this)) - register(SandboxPublicKeySerializer(classLoader, executor)) - register(SandboxToStringSerializer(BigDecimal::class.java, classLoader, executor, sandboxBasicInput)) - register(SandboxToStringSerializer(BigInteger::class.java, classLoader, executor, sandboxBasicInput)) - register(SandboxToStringSerializer(StringBuffer::class.java, classLoader, executor, sandboxBasicInput)) - register(SandboxCurrencySerializer(classLoader, executor, sandboxBasicInput)) - register(SandboxX509CertificateSerializer(classLoader, executor)) - register(SandboxX509CRLSerializer(classLoader, executor)) - register(SandboxUnsignedLongSerializer(classLoader, executor)) - register(SandboxUnsignedIntegerSerializer(classLoader, executor)) - register(SandboxUnsignedShortSerializer(classLoader, executor)) - register(SandboxUnsignedByteSerializer(classLoader, executor)) - register(SandboxDecimal128Serializer(classLoader, executor)) - register(SandboxDecimal64Serializer(classLoader, executor)) - register(SandboxDecimal32Serializer(classLoader, executor)) - register(SandboxSymbolSerializer(classLoader, executor, sandboxBasicInput)) + register(SandboxCollectionSerializer(classLoader, taskFactory, this)) + register(SandboxMapSerializer(classLoader, taskFactory, this)) + register(SandboxEnumSerializer(classLoader, taskFactory, this)) + register(SandboxPublicKeySerializer(classLoader, taskFactory)) + register(SandboxToStringSerializer(BigDecimal::class.java, classLoader, taskFactory, sandboxBasicInput)) + register(SandboxToStringSerializer(BigInteger::class.java, classLoader, taskFactory, sandboxBasicInput)) + register(SandboxToStringSerializer(StringBuffer::class.java, classLoader, taskFactory, sandboxBasicInput)) + register(SandboxCurrencySerializer(classLoader, taskFactory, sandboxBasicInput)) + register(SandboxX509CertificateSerializer(classLoader, taskFactory)) + register(SandboxX509CRLSerializer(classLoader, taskFactory)) + register(SandboxUnsignedLongSerializer(classLoader, taskFactory)) + register(SandboxUnsignedIntegerSerializer(classLoader, taskFactory)) + register(SandboxUnsignedShortSerializer(classLoader, taskFactory)) + register(SandboxUnsignedByteSerializer(classLoader, taskFactory)) + register(SandboxDecimal128Serializer(classLoader, taskFactory)) + register(SandboxDecimal64Serializer(classLoader, taskFactory)) + register(SandboxDecimal32Serializer(classLoader, taskFactory)) + register(SandboxSymbolSerializer(classLoader, taskFactory, sandboxBasicInput)) } } diff --git a/src/main/kotlin/net/corda/djvm/serialization/Serialization.kt b/src/main/kotlin/net/corda/djvm/serialization/Serialization.kt index bd15c6da6c..f286fcf2a8 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/Serialization.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/Serialization.kt @@ -7,22 +7,19 @@ import net.corda.core.serialization.SerializationFactory import net.corda.core.serialization.SerializedBytes import net.corda.core.serialization.internal.SerializationEnvironment import net.corda.core.utilities.ByteSequence -import net.corda.djvm.execution.SandboxRuntimeException import net.corda.djvm.rewiring.SandboxClassLoader import net.corda.djvm.serialization.serializers.PrimitiveSerializer -import net.corda.djvm.source.ClassSource import net.corda.serialization.internal.GlobalTransientClassWhiteList import net.corda.serialization.internal.SerializationContextImpl import net.corda.serialization.internal.SerializationFactoryImpl import net.corda.serialization.internal.amqp.AMQPSerializer import net.corda.serialization.internal.amqp.amqpMagic -import java.lang.reflect.InvocationTargetException -import java.util.function.BiFunction import java.util.function.Function -fun SandboxClassLoader.loadClassForSandbox(clazz: Class<*>): Class { +@Suppress("NOTHING_TO_INLINE") +inline fun SandboxClassLoader.toSandboxAnyClass(clazz: Class<*>): Class { @Suppress("unchecked_cast") - return loadClassForSandbox(ClassSource.fromClassName(clazz.name)) as Class + return toSandboxClass(clazz) as Class } fun createSandboxSerializationEnv(classLoader: SandboxClassLoader): SerializationEnvironment { @@ -37,21 +34,7 @@ fun createSandboxSerializationEnv(classLoader: SandboxClassLoader): Serializatio encoding = null ) - val taskClass = classLoader.loadClass("sandbox.RawTask") - val taskApply = taskClass.getDeclaredMethod("apply", Any::class.java) - val taskConstructor = taskClass.getDeclaredConstructor(classLoader.loadClassForSandbox(Function::class.java)) - val executor: BiFunction = BiFunction { userTask, arg -> - try { - taskApply(taskConstructor.newInstance(userTask), arg) - } catch (ex: InvocationTargetException) { - val target = ex.targetException - throw when (target) { - is RuntimeException, is Error -> target - else -> SandboxRuntimeException(target.message, target) - } - } - } - + val taskFactory = classLoader.createRawTaskFactory() val sandboxBasicInput = classLoader.createBasicInput() val primitiveSerializerFactory: Function, AMQPSerializer> = Function { clazz -> @@ -62,7 +45,7 @@ fun createSandboxSerializationEnv(classLoader: SandboxClassLoader): Serializatio registerScheme(AMQPSerializationScheme( classLoader = classLoader, sandboxBasicInput = sandboxBasicInput, - executor = executor, + taskFactory = taskFactory, serializerFactoryFactory = SandboxSerializerFactoryFactory(primitiveSerializerFactory) )) } @@ -70,7 +53,7 @@ fun createSandboxSerializationEnv(classLoader: SandboxClassLoader): Serializatio } inline fun SerializedBytes.deserializeFor(classLoader: SandboxClassLoader): Any { - val clazz = classLoader.loadClassForSandbox(T::class.java) + val clazz = classLoader.toSandboxClass(T::class.java) return deserializeTo(clazz, classLoader) } diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxBitSetSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxBitSetSerializer.kt index b6a2791944..986bb688d0 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxBitSetSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxBitSetSerializer.kt @@ -2,30 +2,30 @@ package net.corda.djvm.serialization.serializers import net.corda.djvm.rewiring.SandboxClassLoader import net.corda.djvm.serialization.deserializers.BitSetDeserializer -import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.djvm.serialization.toSandboxAnyClass import net.corda.serialization.internal.amqp.CustomSerializer import net.corda.serialization.internal.amqp.SerializerFactory import net.corda.serialization.internal.amqp.custom.BitSetSerializer.BitSetProxy import java.util.* import java.util.Collections.singleton -import java.util.function.BiFunction +import java.util.function.Function class SandboxBitSetSerializer( classLoader: SandboxClassLoader, - private val executor: BiFunction, + taskFactory: Function>, factory: SerializerFactory ) : CustomSerializer.Proxy( - clazz = classLoader.loadClassForSandbox(BitSet::class.java), - proxyClass = classLoader.loadClassForSandbox(BitSetProxy::class.java), + clazz = classLoader.toSandboxAnyClass(BitSet::class.java), + proxyClass = classLoader.toSandboxAnyClass(BitSetProxy::class.java), factory = factory ) { - private val task = classLoader.loadClassForSandbox(BitSetDeserializer::class.java).newInstance() + private val task = classLoader.createTaskFor(taskFactory, BitSetDeserializer::class.java) override val deserializationAliases: Set> = singleton(BitSet::class.java) override fun toProxy(obj: Any): Any = abortReadOnly() override fun fromProxy(proxy: Any): Any { - return executor.apply(task, proxy)!! + return task.apply(proxy)!! } } diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCertPathSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCertPathSerializer.kt index e7380aaeaf..ce916ab671 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCertPathSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCertPathSerializer.kt @@ -2,30 +2,30 @@ package net.corda.djvm.serialization.serializers import net.corda.djvm.rewiring.SandboxClassLoader import net.corda.djvm.serialization.deserializers.CertPathDeserializer -import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.djvm.serialization.toSandboxAnyClass import net.corda.serialization.internal.amqp.CustomSerializer import net.corda.serialization.internal.amqp.SerializerFactory import net.corda.serialization.internal.amqp.custom.CertPathSerializer.CertPathProxy import java.security.cert.CertPath import java.util.Collections.singleton -import java.util.function.BiFunction +import java.util.function.Function class SandboxCertPathSerializer( classLoader: SandboxClassLoader, - private val executor: BiFunction, + taskFactory: Function>, factory: SerializerFactory ) : CustomSerializer.Proxy( - clazz = classLoader.loadClassForSandbox(CertPath::class.java), - proxyClass = classLoader.loadClassForSandbox(CertPathProxy::class.java), + clazz = classLoader.toSandboxAnyClass(CertPath::class.java), + proxyClass = classLoader.toSandboxAnyClass(CertPathProxy::class.java), factory = factory ) { - private val task = classLoader.loadClassForSandbox(CertPathDeserializer::class.java).newInstance() + private val task = classLoader.createTaskFor(taskFactory, CertPathDeserializer::class.java) override val deserializationAliases: Set> = singleton(CertPath::class.java) override fun toProxy(obj: Any): Any = abortReadOnly() override fun fromProxy(proxy: Any): Any { - return executor.apply(task, proxy)!! + return task.apply(proxy)!! } } diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCharacterSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCharacterSerializer.kt index 3793808587..8531d79f1e 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCharacterSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCharacterSerializer.kt @@ -2,7 +2,7 @@ package net.corda.djvm.serialization.serializers import net.corda.core.serialization.SerializationContext import net.corda.djvm.rewiring.SandboxClassLoader -import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.djvm.serialization.toSandboxAnyClass import net.corda.serialization.internal.amqp.* import org.apache.qpid.proton.codec.Data import java.lang.reflect.Type @@ -11,7 +11,7 @@ import java.util.function.Function class SandboxCharacterSerializer( classLoader: SandboxClassLoader, private val basicInput: Function -) : CustomSerializer.Is(classLoader.loadClassForSandbox(Char::class.javaObjectType)) { +) : CustomSerializer.Is(classLoader.toSandboxAnyClass(Char::class.javaObjectType)) { override val schemaForDocumentation: Schema = Schema(emptyList()) diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxClassSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxClassSerializer.kt index 28b275a62a..ebf7270645 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxClassSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxClassSerializer.kt @@ -1,27 +1,25 @@ package net.corda.djvm.serialization.serializers -import net.corda.djvm.execution.SandboxRuntimeException import net.corda.djvm.rewiring.SandboxClassLoader import net.corda.djvm.serialization.deserializers.ClassDeserializer -import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.djvm.serialization.toSandboxAnyClass import net.corda.serialization.internal.amqp.AMQPNotSerializableException import net.corda.serialization.internal.amqp.CustomSerializer import net.corda.serialization.internal.amqp.SerializerFactory import net.corda.serialization.internal.amqp.custom.ClassSerializer.ClassProxy -import java.util.function.BiFunction import java.util.function.Function @Suppress("unchecked_cast") class SandboxClassSerializer( classLoader: SandboxClassLoader, - private val executor: BiFunction, + taskFactory: Function>, factory: SerializerFactory ) : CustomSerializer.Proxy( clazz = Class::class.java as Class, - proxyClass = classLoader.loadClassForSandbox(ClassProxy::class.java), + proxyClass = classLoader.toSandboxAnyClass(ClassProxy::class.java), factory = factory ) { - private val task = classLoader.loadClassForSandbox(ClassDeserializer::class.java).newInstance() + private val task = classLoader.createTaskFor(taskFactory, ClassDeserializer::class.java) private val nameOf: Function init { @@ -35,13 +33,8 @@ class SandboxClassSerializer( override fun fromProxy(proxy: Any): Any { return try { - executor.apply(task, proxy)!! - } catch (e: SandboxRuntimeException) { - val cause = e.cause ?: throw e - if (cause !is ClassNotFoundException) { - throw cause - } - + task.apply(proxy)!! + } catch (e: ClassNotFoundException) { val className = nameOf.apply(proxy) throw AMQPNotSerializableException(type, "Could not instantiate $className - not on the classpath", diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCollectionSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCollectionSerializer.kt index 3aad78113f..a7b195098b 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCollectionSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCollectionSerializer.kt @@ -4,7 +4,7 @@ import net.corda.core.serialization.SerializationContext import net.corda.core.utilities.NonEmptySet import net.corda.djvm.rewiring.SandboxClassLoader import net.corda.djvm.serialization.deserializers.CreateCollection -import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.djvm.serialization.toSandboxAnyClass import net.corda.serialization.internal.amqp.* import net.corda.serialization.internal.model.LocalTypeInformation import net.corda.serialization.internal.model.TypeIdentifier @@ -13,27 +13,21 @@ import org.apache.qpid.proton.codec.Data import java.lang.reflect.ParameterizedType import java.lang.reflect.Type import java.util.* -import java.util.function.BiFunction import java.util.function.Function class SandboxCollectionSerializer( classLoader: SandboxClassLoader, - executor: BiFunction, + taskFactory: Function>, private val localFactory: LocalSerializerFactory -) : CustomSerializer.Implements(clazz = classLoader.loadClassForSandbox(Collection::class.java)) { +) : CustomSerializer.Implements(clazz = classLoader.toSandboxAnyClass(Collection::class.java)) { + @Suppress("unchecked_cast") private val creator: Function, out Any?> - - init { - val createTask = classLoader.loadClassForSandbox(CreateCollection::class.java).newInstance() - creator = Function { inputs -> - executor.apply(createTask, inputs) - } - } + = classLoader.createTaskFor(taskFactory, CreateCollection::class.java) as Function, out Any?> private val unsupportedTypes: Set> = listOf( EnumSet::class.java ).map { - classLoader.loadClassForSandbox(it) + classLoader.toSandboxAnyClass(it) }.toSet() // The order matters here - the first match should be the most specific one. @@ -46,7 +40,7 @@ class SandboxCollectionSerializer( Set::class.java, Collection::class.java ).associateBy { - classLoader.loadClassForSandbox(it) + classLoader.toSandboxAnyClass(it) } private fun getBestMatchFor(type: Class): Map.Entry, Class>> diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCurrencySerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCurrencySerializer.kt index 9eee16cb33..6bb3f90360 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCurrencySerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCurrencySerializer.kt @@ -3,29 +3,27 @@ package net.corda.djvm.serialization.serializers import net.corda.core.serialization.SerializationContext import net.corda.djvm.rewiring.SandboxClassLoader import net.corda.djvm.serialization.deserializers.CreateCurrency -import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.djvm.serialization.toSandboxAnyClass import net.corda.serialization.internal.amqp.* import org.apache.qpid.proton.codec.Data import java.lang.reflect.Type import java.util.* -import java.util.function.BiFunction +import java.util.Collections.singleton import java.util.function.Function class SandboxCurrencySerializer( classLoader: SandboxClassLoader, - executor: BiFunction, + taskFactory: Function>, basicInput: Function -) : CustomSerializer.Is(classLoader.loadClassForSandbox(Currency::class.java)) { +) : CustomSerializer.Is(classLoader.toSandboxAnyClass(Currency::class.java)) { private val creator: Function init { - val createTask = classLoader.loadClassForSandbox(CreateCurrency::class.java).newInstance() - creator = basicInput.andThen { input -> - executor.apply(createTask, input) - } + val createTask = classLoader.createTaskFor(taskFactory, CreateCurrency::class.java) + creator = basicInput.andThen(createTask) } - override val deserializationAliases: Set> = Collections.singleton(Currency::class.java) + override val deserializationAliases: Set> = singleton(Currency::class.java) override val schemaForDocumentation: Schema = Schema(emptyList()) diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDecimal128Serializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDecimal128Serializer.kt index 7f5da69f5e..283700a8fb 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDecimal128Serializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDecimal128Serializer.kt @@ -3,26 +3,20 @@ package net.corda.djvm.serialization.serializers import net.corda.core.serialization.SerializationContext import net.corda.djvm.rewiring.SandboxClassLoader import net.corda.djvm.serialization.deserializers.Decimal128Deserializer -import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.djvm.serialization.toSandboxAnyClass import net.corda.serialization.internal.amqp.* import org.apache.qpid.proton.amqp.Decimal128 import org.apache.qpid.proton.codec.Data import java.lang.reflect.Type -import java.util.function.BiFunction import java.util.function.Function class SandboxDecimal128Serializer( classLoader: SandboxClassLoader, - executor: BiFunction -) : CustomSerializer.Is(classLoader.loadClassForSandbox(Decimal128::class.java)) { + taskFactory: Function> +) : CustomSerializer.Is(classLoader.toSandboxAnyClass(Decimal128::class.java)) { + @Suppress("unchecked_cast") private val transformer: Function - - init { - val transformTask = classLoader.loadClassForSandbox(Decimal128Deserializer::class.java).newInstance() - transformer = Function { inputs -> - executor.apply(transformTask, inputs) - } - } + = classLoader.createTaskFor(taskFactory, Decimal128Deserializer::class.java) as Function override val schemaForDocumentation: Schema = Schema(emptyList()) diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDecimal32Serializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDecimal32Serializer.kt index d0d8016683..4037b5e9b6 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDecimal32Serializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDecimal32Serializer.kt @@ -3,26 +3,20 @@ package net.corda.djvm.serialization.serializers import net.corda.core.serialization.SerializationContext import net.corda.djvm.rewiring.SandboxClassLoader import net.corda.djvm.serialization.deserializers.Decimal32Deserializer -import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.djvm.serialization.toSandboxAnyClass import net.corda.serialization.internal.amqp.* import org.apache.qpid.proton.amqp.Decimal32 import org.apache.qpid.proton.codec.Data import java.lang.reflect.Type -import java.util.function.BiFunction import java.util.function.Function class SandboxDecimal32Serializer( classLoader: SandboxClassLoader, - executor: BiFunction -) : CustomSerializer.Is(classLoader.loadClassForSandbox(Decimal32::class.java)) { + taskFactory: Function> +) : CustomSerializer.Is(classLoader.toSandboxAnyClass(Decimal32::class.java)) { + @Suppress("unchecked_cast") private val transformer: Function - - init { - val transformTask = classLoader.loadClassForSandbox(Decimal32Deserializer::class.java).newInstance() - transformer = Function { inputs -> - executor.apply(transformTask, inputs) - } - } + = classLoader.createTaskFor(taskFactory, Decimal32Deserializer::class.java) as Function override val schemaForDocumentation: Schema = Schema(emptyList()) diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDecimal64Serializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDecimal64Serializer.kt index c77820712d..e10967e0b3 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDecimal64Serializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDecimal64Serializer.kt @@ -3,26 +3,20 @@ package net.corda.djvm.serialization.serializers import net.corda.core.serialization.SerializationContext import net.corda.djvm.rewiring.SandboxClassLoader import net.corda.djvm.serialization.deserializers.Decimal64Deserializer -import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.djvm.serialization.toSandboxAnyClass import net.corda.serialization.internal.amqp.* import org.apache.qpid.proton.amqp.Decimal64 import org.apache.qpid.proton.codec.Data import java.lang.reflect.Type -import java.util.function.BiFunction import java.util.function.Function class SandboxDecimal64Serializer( classLoader: SandboxClassLoader, - executor: BiFunction -) : CustomSerializer.Is(classLoader.loadClassForSandbox(Decimal64::class.java)) { + taskFactory: Function> +) : CustomSerializer.Is(classLoader.toSandboxAnyClass(Decimal64::class.java)) { + @Suppress("unchecked_cast") private val transformer: Function - - init { - val transformTask = classLoader.loadClassForSandbox(Decimal64Deserializer::class.java).newInstance() - transformer = Function { inputs -> - executor.apply(transformTask, inputs) - } - } + = classLoader.createTaskFor(taskFactory, Decimal64Deserializer::class.java) as Function override val schemaForDocumentation: Schema = Schema(emptyList()) diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDurationSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDurationSerializer.kt index 48586ce4df..d1ab4eb2ab 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDurationSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDurationSerializer.kt @@ -2,30 +2,30 @@ package net.corda.djvm.serialization.serializers import net.corda.djvm.rewiring.SandboxClassLoader import net.corda.djvm.serialization.deserializers.DurationDeserializer -import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.djvm.serialization.toSandboxAnyClass import net.corda.serialization.internal.amqp.CustomSerializer import net.corda.serialization.internal.amqp.SerializerFactory import net.corda.serialization.internal.amqp.custom.DurationSerializer.DurationProxy import java.time.Duration import java.util.Collections.singleton -import java.util.function.BiFunction +import java.util.function.Function class SandboxDurationSerializer( classLoader: SandboxClassLoader, - private val executor: BiFunction, + taskFactory: Function>, factory: SerializerFactory ) : CustomSerializer.Proxy( - clazz = classLoader.loadClassForSandbox(Duration::class.java), - proxyClass = classLoader.loadClassForSandbox(DurationProxy::class.java), + clazz = classLoader.toSandboxAnyClass(Duration::class.java), + proxyClass = classLoader.toSandboxAnyClass(DurationProxy::class.java), factory = factory ) { - private val task = classLoader.loadClassForSandbox(DurationDeserializer::class.java).newInstance() + private val task = classLoader.createTaskFor(taskFactory, DurationDeserializer::class.java) override val deserializationAliases: Set> = singleton(Duration::class.java) override fun toProxy(obj: Any): Any = abortReadOnly() override fun fromProxy(proxy: Any): Any { - return executor.apply(task, proxy)!! + return task.apply(proxy)!! } } diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxEnumSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxEnumSerializer.kt index fedb92450a..6729ca0c4c 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxEnumSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxEnumSerializer.kt @@ -3,7 +3,7 @@ package net.corda.djvm.serialization.serializers import net.corda.core.serialization.SerializationContext import net.corda.djvm.rewiring.SandboxClassLoader import net.corda.djvm.serialization.deserializers.DescribeEnum -import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.djvm.serialization.toSandboxAnyClass import net.corda.serialization.internal.amqp.* import net.corda.serialization.internal.model.EnumTransforms import net.corda.serialization.internal.model.LocalTypeInformation @@ -11,23 +11,16 @@ import net.corda.serialization.internal.model.TypeIdentifier import org.apache.qpid.proton.amqp.Symbol import org.apache.qpid.proton.codec.Data import java.lang.reflect.Type -import java.util.function.BiFunction import java.util.function.Function class SandboxEnumSerializer( classLoader: SandboxClassLoader, - executor: BiFunction, + taskFactory: Function>, private val localFactory: LocalSerializerFactory -) : CustomSerializer.Implements(clazz = classLoader.loadClassForSandbox(Enum::class.java)) { +) : CustomSerializer.Implements(clazz = classLoader.toSandboxAnyClass(Enum::class.java)) { + @Suppress("unchecked_cast") private val describer: Function, Array> - - init { - val describeTask = classLoader.loadClassForSandbox(DescribeEnum::class.java).newInstance() - describer = Function { inputs -> - @Suppress("unchecked_cast") - executor.apply(describeTask, inputs) as Array - } - } + = classLoader.createTaskFor(taskFactory, DescribeEnum::class.java) as Function, Array> override val schemaForDocumentation: Schema = Schema(emptyList()) diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxEnumSetSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxEnumSetSerializer.kt index fe839f2b5c..1d0fa576d6 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxEnumSetSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxEnumSetSerializer.kt @@ -2,27 +2,27 @@ package net.corda.djvm.serialization.serializers import net.corda.djvm.rewiring.SandboxClassLoader import net.corda.djvm.serialization.deserializers.EnumSetDeserializer -import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.djvm.serialization.toSandboxAnyClass import net.corda.serialization.internal.amqp.CustomSerializer import net.corda.serialization.internal.amqp.SerializerFactory import net.corda.serialization.internal.amqp.custom.EnumSetSerializer.EnumSetProxy import java.util.* import java.util.Collections.singleton -import java.util.function.BiFunction +import java.util.function.Function class SandboxEnumSetSerializer( classLoader: SandboxClassLoader, - private val executor: BiFunction, + taskFactory: Function>, factory: SerializerFactory ) : CustomSerializer.Proxy( - clazz = classLoader.loadClassForSandbox(EnumSet::class.java), - proxyClass = classLoader.loadClassForSandbox(EnumSetProxy::class.java), + clazz = classLoader.toSandboxAnyClass(EnumSet::class.java), + proxyClass = classLoader.toSandboxAnyClass(EnumSetProxy::class.java), factory = factory ) { - private val task = classLoader.loadClassForSandbox(EnumSetDeserializer::class.java).newInstance() + private val task = classLoader.createTaskFor(taskFactory, EnumSetDeserializer::class.java) override val additionalSerializers: Set> = singleton( - SandboxClassSerializer(classLoader, executor, factory) + SandboxClassSerializer(classLoader, taskFactory, factory) ) override val deserializationAliases: Set> = singleton(EnumSet::class.java) @@ -30,6 +30,6 @@ class SandboxEnumSetSerializer( override fun toProxy(obj: Any): Any = abortReadOnly() override fun fromProxy(proxy: Any): Any { - return executor.apply(task, proxy)!! + return task.apply(proxy)!! } } diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxInputStreamSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxInputStreamSerializer.kt index c7b6465072..c4f944d4bd 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxInputStreamSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxInputStreamSerializer.kt @@ -3,27 +3,21 @@ package net.corda.djvm.serialization.serializers import net.corda.core.serialization.SerializationContext import net.corda.djvm.rewiring.SandboxClassLoader import net.corda.djvm.serialization.deserializers.InputStreamDeserializer -import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.djvm.serialization.toSandboxAnyClass import net.corda.serialization.internal.amqp.* import org.apache.qpid.proton.codec.Data import java.io.InputStream import java.lang.reflect.Type import java.util.Collections.singleton -import java.util.function.BiFunction import java.util.function.Function class SandboxInputStreamSerializer( classLoader: SandboxClassLoader, - executor: BiFunction -) : CustomSerializer.Implements(classLoader.loadClassForSandbox(InputStream::class.java)) { + taskFactory: Function> +) : CustomSerializer.Implements(classLoader.toSandboxAnyClass(InputStream::class.java)) { + @Suppress("unchecked_cast") private val decoder: Function - - init { - val decodeTask = classLoader.loadClassForSandbox(InputStreamDeserializer::class.java).newInstance() - decoder = Function { inputs -> - executor.apply(decodeTask, inputs) - } - } + = classLoader.createTaskFor(taskFactory, InputStreamDeserializer::class.java) as Function override val schemaForDocumentation: Schema = Schema(emptyList()) diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxInstantSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxInstantSerializer.kt index ea867b146a..452b6d1066 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxInstantSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxInstantSerializer.kt @@ -2,30 +2,30 @@ package net.corda.djvm.serialization.serializers import net.corda.djvm.rewiring.SandboxClassLoader import net.corda.djvm.serialization.deserializers.InstantDeserializer -import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.djvm.serialization.toSandboxAnyClass import net.corda.serialization.internal.amqp.CustomSerializer import net.corda.serialization.internal.amqp.SerializerFactory import net.corda.serialization.internal.amqp.custom.InstantSerializer.InstantProxy import java.time.Instant import java.util.Collections.singleton -import java.util.function.BiFunction +import java.util.function.Function class SandboxInstantSerializer( classLoader: SandboxClassLoader, - private val executor: BiFunction, + taskFactory: Function>, factory: SerializerFactory ) : CustomSerializer.Proxy( - clazz = classLoader.loadClassForSandbox(Instant::class.java), - proxyClass = classLoader.loadClassForSandbox(InstantProxy::class.java), + clazz = classLoader.toSandboxAnyClass(Instant::class.java), + proxyClass = classLoader.toSandboxAnyClass(InstantProxy::class.java), factory = factory ) { - private val task = classLoader.loadClassForSandbox(InstantDeserializer::class.java).newInstance() + private val task = classLoader.createTaskFor(taskFactory, InstantDeserializer::class.java) override val deserializationAliases: Set> = singleton(Instant::class.java) override fun toProxy(obj: Any): Any = abortReadOnly() override fun fromProxy(proxy: Any): Any { - return executor.apply(task, proxy)!! + return task.apply(proxy)!! } } diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxLocalDateSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxLocalDateSerializer.kt index 4a8cbb256b..11c324c03e 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxLocalDateSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxLocalDateSerializer.kt @@ -2,30 +2,30 @@ package net.corda.djvm.serialization.serializers import net.corda.djvm.rewiring.SandboxClassLoader import net.corda.djvm.serialization.deserializers.LocalDateDeserializer -import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.djvm.serialization.toSandboxAnyClass import net.corda.serialization.internal.amqp.CustomSerializer import net.corda.serialization.internal.amqp.SerializerFactory import net.corda.serialization.internal.amqp.custom.LocalDateSerializer.LocalDateProxy import java.time.LocalDate import java.util.Collections.singleton -import java.util.function.BiFunction +import java.util.function.Function class SandboxLocalDateSerializer( classLoader: SandboxClassLoader, - private val executor: BiFunction, + taskFactory: Function>, factory: SerializerFactory ) : CustomSerializer.Proxy( - clazz = classLoader.loadClassForSandbox(LocalDate::class.java), - proxyClass = classLoader.loadClassForSandbox(LocalDateProxy::class.java), + clazz = classLoader.toSandboxAnyClass(LocalDate::class.java), + proxyClass = classLoader.toSandboxAnyClass(LocalDateProxy::class.java), factory = factory ) { - private val task = classLoader.loadClassForSandbox(LocalDateDeserializer::class.java).newInstance() + private val task = classLoader.createTaskFor(taskFactory, LocalDateDeserializer::class.java) override val deserializationAliases: Set> = singleton(LocalDate::class.java) override fun toProxy(obj: Any): Any = abortReadOnly() override fun fromProxy(proxy: Any): Any { - return executor.apply(task, proxy)!! + return task.apply(proxy)!! } } diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxLocalDateTimeSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxLocalDateTimeSerializer.kt index d027a5b61c..af2a832027 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxLocalDateTimeSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxLocalDateTimeSerializer.kt @@ -2,30 +2,30 @@ package net.corda.djvm.serialization.serializers import net.corda.djvm.rewiring.SandboxClassLoader import net.corda.djvm.serialization.deserializers.LocalDateTimeDeserializer -import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.djvm.serialization.toSandboxAnyClass import net.corda.serialization.internal.amqp.CustomSerializer import net.corda.serialization.internal.amqp.SerializerFactory import net.corda.serialization.internal.amqp.custom.LocalDateTimeSerializer.LocalDateTimeProxy import java.time.LocalDateTime import java.util.Collections.singleton -import java.util.function.BiFunction +import java.util.function.Function class SandboxLocalDateTimeSerializer( classLoader: SandboxClassLoader, - private val executor: BiFunction, + taskFactory: Function>, factory: SerializerFactory ) : CustomSerializer.Proxy( - clazz = classLoader.loadClassForSandbox(LocalDateTime::class.java), - proxyClass = classLoader.loadClassForSandbox(LocalDateTimeProxy::class.java), + clazz = classLoader.toSandboxAnyClass(LocalDateTime::class.java), + proxyClass = classLoader.toSandboxAnyClass(LocalDateTimeProxy::class.java), factory = factory ) { - private val task = classLoader.loadClassForSandbox(LocalDateTimeDeserializer::class.java).newInstance() + private val task = classLoader.createTaskFor(taskFactory, LocalDateTimeDeserializer::class.java) override val deserializationAliases: Set> = singleton(LocalDateTime::class.java) override fun toProxy(obj: Any): Any = abortReadOnly() override fun fromProxy(proxy: Any): Any { - return executor.apply(task, proxy)!! + return task.apply(proxy)!! } } diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxLocalTimeSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxLocalTimeSerializer.kt index 87dfa15e26..ab54302539 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxLocalTimeSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxLocalTimeSerializer.kt @@ -2,30 +2,30 @@ package net.corda.djvm.serialization.serializers import net.corda.djvm.rewiring.SandboxClassLoader import net.corda.djvm.serialization.deserializers.LocalTimeDeserializer -import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.djvm.serialization.toSandboxAnyClass import net.corda.serialization.internal.amqp.CustomSerializer import net.corda.serialization.internal.amqp.SerializerFactory import net.corda.serialization.internal.amqp.custom.LocalTimeSerializer.LocalTimeProxy import java.time.LocalTime import java.util.Collections.singleton -import java.util.function.BiFunction +import java.util.function.Function class SandboxLocalTimeSerializer( classLoader: SandboxClassLoader, - private val executor: BiFunction, + taskFactory: Function>, factory: SerializerFactory ) : CustomSerializer.Proxy( - clazz = classLoader.loadClassForSandbox(LocalTime::class.java), - proxyClass = classLoader.loadClassForSandbox(LocalTimeProxy::class.java), + clazz = classLoader.toSandboxAnyClass(LocalTime::class.java), + proxyClass = classLoader.toSandboxAnyClass(LocalTimeProxy::class.java), factory = factory ) { - private val task = classLoader.loadClassForSandbox(LocalTimeDeserializer::class.java).newInstance() + private val task = classLoader.createTaskFor(taskFactory, LocalTimeDeserializer::class.java) override val deserializationAliases: Set> = singleton(LocalTime::class.java) override fun toProxy(obj: Any): Any = abortReadOnly() override fun fromProxy(proxy: Any): Any { - return executor.apply(task, proxy)!! + return task.apply(proxy)!! } } diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxMapSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxMapSerializer.kt index 2489b53742..c718147799 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxMapSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxMapSerializer.kt @@ -3,7 +3,7 @@ package net.corda.djvm.serialization.serializers import net.corda.core.serialization.SerializationContext import net.corda.djvm.rewiring.SandboxClassLoader import net.corda.djvm.serialization.deserializers.CreateMap -import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.djvm.serialization.toSandboxAnyClass import net.corda.serialization.internal.amqp.* import net.corda.serialization.internal.model.LocalTypeInformation import net.corda.serialization.internal.model.TypeIdentifier @@ -12,22 +12,16 @@ import org.apache.qpid.proton.codec.Data import java.lang.reflect.ParameterizedType import java.lang.reflect.Type import java.util.* -import java.util.function.BiFunction import java.util.function.Function class SandboxMapSerializer( classLoader: SandboxClassLoader, - executor: BiFunction, + taskFactory: Function>, private val localFactory: LocalSerializerFactory -) : CustomSerializer.Implements(clazz = classLoader.loadClassForSandbox(Map::class.java)) { +) : CustomSerializer.Implements(clazz = classLoader.toSandboxAnyClass(Map::class.java)) { + @Suppress("unchecked_cast") private val creator: Function, out Any?> - - init { - val createTask = classLoader.loadClassForSandbox(CreateMap::class.java).newInstance() - creator = Function { inputs -> - executor.apply(createTask, inputs) - } - } + = classLoader.createTaskFor(taskFactory, CreateMap::class.java) as Function, out Any?> // The order matters here - the first match should be the most specific one. // Kotlin preserves the ordering for us by associating into a LinkedHashMap. @@ -39,7 +33,7 @@ class SandboxMapSerializer( EnumMap::class.java, Map::class.java ).associateBy { - classLoader.loadClassForSandbox(it) + classLoader.toSandboxAnyClass(it) } private fun getBestMatchFor(type: Class): Map.Entry, Class>> diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxMonthDaySerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxMonthDaySerializer.kt index cd489228b2..c42c13946b 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxMonthDaySerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxMonthDaySerializer.kt @@ -2,30 +2,30 @@ package net.corda.djvm.serialization.serializers import net.corda.djvm.rewiring.SandboxClassLoader import net.corda.djvm.serialization.deserializers.MonthDayDeserializer -import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.djvm.serialization.toSandboxAnyClass import net.corda.serialization.internal.amqp.CustomSerializer import net.corda.serialization.internal.amqp.SerializerFactory import net.corda.serialization.internal.amqp.custom.MonthDaySerializer.MonthDayProxy import java.time.MonthDay import java.util.Collections.singleton -import java.util.function.BiFunction +import java.util.function.Function class SandboxMonthDaySerializer( classLoader: SandboxClassLoader, - private val executor: BiFunction, + taskFactory: Function>, factory: SerializerFactory ) : CustomSerializer.Proxy( - clazz = classLoader.loadClassForSandbox(MonthDay::class.java), - proxyClass = classLoader.loadClassForSandbox(MonthDayProxy::class.java), + clazz = classLoader.toSandboxAnyClass(MonthDay::class.java), + proxyClass = classLoader.toSandboxAnyClass(MonthDayProxy::class.java), factory = factory ) { - private val task = classLoader.loadClassForSandbox(MonthDayDeserializer::class.java).newInstance() + private val task = classLoader.createTaskFor(taskFactory, MonthDayDeserializer::class.java) override val deserializationAliases: Set> = singleton(MonthDay::class.java) override fun toProxy(obj: Any): Any = abortReadOnly() override fun fromProxy(proxy: Any): Any { - return executor.apply(task, proxy)!! + return task.apply(proxy)!! } } diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOffsetDateTimeSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOffsetDateTimeSerializer.kt index 54091ab2be..58dd564ca6 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOffsetDateTimeSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOffsetDateTimeSerializer.kt @@ -2,30 +2,30 @@ package net.corda.djvm.serialization.serializers import net.corda.djvm.rewiring.SandboxClassLoader import net.corda.djvm.serialization.deserializers.OffsetDateTimeDeserializer -import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.djvm.serialization.toSandboxAnyClass import net.corda.serialization.internal.amqp.CustomSerializer import net.corda.serialization.internal.amqp.SerializerFactory import net.corda.serialization.internal.amqp.custom.OffsetDateTimeSerializer.OffsetDateTimeProxy import java.time.OffsetDateTime import java.util.Collections.singleton -import java.util.function.BiFunction +import java.util.function.Function class SandboxOffsetDateTimeSerializer( classLoader: SandboxClassLoader, - private val executor: BiFunction, + taskFactory: Function>, factory: SerializerFactory ) : CustomSerializer.Proxy( - clazz = classLoader.loadClassForSandbox(OffsetDateTime::class.java), - proxyClass = classLoader.loadClassForSandbox(OffsetDateTimeProxy::class.java), + clazz = classLoader.toSandboxAnyClass(OffsetDateTime::class.java), + proxyClass = classLoader.toSandboxAnyClass(OffsetDateTimeProxy::class.java), factory = factory ) { - private val task = classLoader.loadClassForSandbox(OffsetDateTimeDeserializer::class.java).newInstance() + private val task = classLoader.createTaskFor(taskFactory, OffsetDateTimeDeserializer::class.java) override val deserializationAliases: Set> = singleton(OffsetDateTime::class.java) override fun toProxy(obj: Any): Any = abortReadOnly() override fun fromProxy(proxy: Any): Any { - return executor.apply(task, proxy)!! + return task.apply(proxy)!! } } diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOffsetTimeSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOffsetTimeSerializer.kt index 284465a4de..e452a281ef 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOffsetTimeSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOffsetTimeSerializer.kt @@ -2,30 +2,30 @@ package net.corda.djvm.serialization.serializers import net.corda.djvm.rewiring.SandboxClassLoader import net.corda.djvm.serialization.deserializers.OffsetTimeDeserializer -import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.djvm.serialization.toSandboxAnyClass import net.corda.serialization.internal.amqp.CustomSerializer import net.corda.serialization.internal.amqp.SerializerFactory import net.corda.serialization.internal.amqp.custom.OffsetTimeSerializer.OffsetTimeProxy import java.time.OffsetTime import java.util.Collections.singleton -import java.util.function.BiFunction +import java.util.function.Function class SandboxOffsetTimeSerializer( classLoader: SandboxClassLoader, - private val executor: BiFunction, + taskFactory: Function>, factory: SerializerFactory ) : CustomSerializer.Proxy( - clazz = classLoader.loadClassForSandbox(OffsetTime::class.java), - proxyClass = classLoader.loadClassForSandbox(OffsetTimeProxy::class.java), + clazz = classLoader.toSandboxAnyClass(OffsetTime::class.java), + proxyClass = classLoader.toSandboxAnyClass(OffsetTimeProxy::class.java), factory = factory ) { - private val task = classLoader.loadClassForSandbox(OffsetTimeDeserializer::class.java).newInstance() + private val task = classLoader.createTaskFor(taskFactory, OffsetTimeDeserializer::class.java) override val deserializationAliases: Set> = singleton(OffsetTime::class.java) override fun toProxy(obj: Any): Any = abortReadOnly() override fun fromProxy(proxy: Any): Any { - return executor.apply(task, proxy)!! + return task.apply(proxy)!! } } diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOpaqueBytesSubSequenceSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOpaqueBytesSubSequenceSerializer.kt index 7d41b81930..944cf19437 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOpaqueBytesSubSequenceSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOpaqueBytesSubSequenceSerializer.kt @@ -4,28 +4,28 @@ import net.corda.core.utilities.OpaqueBytes import net.corda.core.utilities.OpaqueBytesSubSequence import net.corda.djvm.rewiring.SandboxClassLoader import net.corda.djvm.serialization.deserializers.OpaqueBytesSubSequenceDeserializer -import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.djvm.serialization.toSandboxAnyClass import net.corda.serialization.internal.amqp.CustomSerializer import net.corda.serialization.internal.amqp.SerializerFactory import java.util.Collections.singleton -import java.util.function.BiFunction +import java.util.function.Function class SandboxOpaqueBytesSubSequenceSerializer( classLoader: SandboxClassLoader, - private val executor: BiFunction, + taskFactory: Function>, factory: SerializerFactory ) : CustomSerializer.Proxy( - clazz = classLoader.loadClassForSandbox(OpaqueBytesSubSequence::class.java), - proxyClass = classLoader.loadClassForSandbox(OpaqueBytes::class.java), + clazz = classLoader.toSandboxAnyClass(OpaqueBytesSubSequence::class.java), + proxyClass = classLoader.toSandboxAnyClass(OpaqueBytes::class.java), factory = factory ) { - private val task = classLoader.loadClassForSandbox(OpaqueBytesSubSequenceDeserializer::class.java).newInstance() + private val task = classLoader.createTaskFor(taskFactory, OpaqueBytesSubSequenceDeserializer::class.java) override val deserializationAliases: Set> = singleton(OpaqueBytesSubSequence::class.java) override fun toProxy(obj: Any): Any = abortReadOnly() override fun fromProxy(proxy: Any): Any { - return executor.apply(task, proxy)!! + return task.apply(proxy)!! } } diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOptionalSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOptionalSerializer.kt index 733ceabc93..39eeb015a7 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOptionalSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOptionalSerializer.kt @@ -2,30 +2,30 @@ package net.corda.djvm.serialization.serializers import net.corda.djvm.rewiring.SandboxClassLoader import net.corda.djvm.serialization.deserializers.OptionalDeserializer -import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.djvm.serialization.toSandboxAnyClass import net.corda.serialization.internal.amqp.CustomSerializer import net.corda.serialization.internal.amqp.SerializerFactory import net.corda.serialization.internal.amqp.custom.OptionalSerializer.OptionalProxy import java.util.* import java.util.Collections.singleton -import java.util.function.BiFunction +import java.util.function.Function class SandboxOptionalSerializer( classLoader: SandboxClassLoader, - private val executor: BiFunction, + taskFactory: Function>, factory: SerializerFactory ) : CustomSerializer.Proxy( - clazz = classLoader.loadClassForSandbox(Optional::class.java), - proxyClass = classLoader.loadClassForSandbox(OptionalProxy::class.java), + clazz = classLoader.toSandboxAnyClass(Optional::class.java), + proxyClass = classLoader.toSandboxAnyClass(OptionalProxy::class.java), factory = factory ) { - private val task = classLoader.loadClassForSandbox(OptionalDeserializer::class.java).newInstance() + private val task = classLoader.createTaskFor(taskFactory, OptionalDeserializer::class.java) override val deserializationAliases: Set> = singleton(Optional::class.java) override fun toProxy(obj: Any): Any = abortReadOnly() override fun fromProxy(proxy: Any): Any { - return executor.apply(task, proxy)!! + return task.apply(proxy)!! } } diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxPeriodSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxPeriodSerializer.kt index 31ad835f1c..836acbb3ca 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxPeriodSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxPeriodSerializer.kt @@ -2,30 +2,30 @@ package net.corda.djvm.serialization.serializers import net.corda.djvm.rewiring.SandboxClassLoader import net.corda.djvm.serialization.deserializers.PeriodDeserializer -import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.djvm.serialization.toSandboxAnyClass import net.corda.serialization.internal.amqp.CustomSerializer import net.corda.serialization.internal.amqp.SerializerFactory import net.corda.serialization.internal.amqp.custom.PeriodSerializer.PeriodProxy import java.time.Period import java.util.Collections.singleton -import java.util.function.BiFunction +import java.util.function.Function class SandboxPeriodSerializer( classLoader: SandboxClassLoader, - private val executor: BiFunction, + taskFactory: Function>, factory: SerializerFactory ) : CustomSerializer.Proxy( - clazz = classLoader.loadClassForSandbox(Period::class.java), - proxyClass = classLoader.loadClassForSandbox(PeriodProxy::class.java), + clazz = classLoader.toSandboxAnyClass(Period::class.java), + proxyClass = classLoader.toSandboxAnyClass(PeriodProxy::class.java), factory = factory ) { - private val task = classLoader.loadClassForSandbox(PeriodDeserializer::class.java).newInstance() + private val task = classLoader.createTaskFor(taskFactory, PeriodDeserializer::class.java) override val deserializationAliases: Set> = singleton(Period::class.java) override fun toProxy(obj: Any): Any = abortReadOnly() override fun fromProxy(proxy: Any): Any { - return executor.apply(task, proxy)!! + return task.apply(proxy)!! } } diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxPrimitiveSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxPrimitiveSerializer.kt index b5eeb43927..6499d6cb5a 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxPrimitiveSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxPrimitiveSerializer.kt @@ -2,7 +2,7 @@ package net.corda.djvm.serialization.serializers import net.corda.core.serialization.SerializationContext import net.corda.djvm.rewiring.SandboxClassLoader -import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.djvm.serialization.toSandboxAnyClass import net.corda.serialization.internal.amqp.* import org.apache.qpid.proton.codec.Data import java.lang.reflect.Type @@ -12,7 +12,7 @@ class SandboxPrimitiveSerializer( clazz: Class<*>, classLoader: SandboxClassLoader, private val basicInput: Function -) : CustomSerializer.Is(classLoader.loadClassForSandbox(clazz)) { +) : CustomSerializer.Is(classLoader.toSandboxAnyClass(clazz)) { override val schemaForDocumentation: Schema = Schema(emptyList()) diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxPublicKeySerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxPublicKeySerializer.kt index 4bbca81690..1806f43f2c 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxPublicKeySerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxPublicKeySerializer.kt @@ -3,27 +3,21 @@ package net.corda.djvm.serialization.serializers import net.corda.core.serialization.SerializationContext import net.corda.djvm.rewiring.SandboxClassLoader import net.corda.djvm.serialization.deserializers.PublicKeyDecoder -import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.djvm.serialization.toSandboxAnyClass import net.corda.serialization.internal.amqp.* import org.apache.qpid.proton.codec.Data import java.lang.reflect.Type import java.security.PublicKey import java.util.Collections.singleton -import java.util.function.BiFunction import java.util.function.Function class SandboxPublicKeySerializer( classLoader: SandboxClassLoader, - executor: BiFunction -) : CustomSerializer.Implements(classLoader.loadClassForSandbox(PublicKey::class.java)) { + taskFactory: Function> +) : CustomSerializer.Implements(classLoader.toSandboxAnyClass(PublicKey::class.java)) { + @Suppress("unchecked_cast") private val decoder: Function - - init { - val decodeTask = classLoader.loadClassForSandbox(PublicKeyDecoder::class.java).newInstance() - decoder = Function { inputs -> - executor.apply(decodeTask, inputs) - } - } + = classLoader.createTaskFor(taskFactory, PublicKeyDecoder::class.java) as Function override val schemaForDocumentation: Schema = Schema(emptyList()) diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxSymbolSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxSymbolSerializer.kt index 95ce4a7694..ade7c033b3 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxSymbolSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxSymbolSerializer.kt @@ -3,27 +3,24 @@ package net.corda.djvm.serialization.serializers import net.corda.core.serialization.SerializationContext import net.corda.djvm.rewiring.SandboxClassLoader import net.corda.djvm.serialization.deserializers.SymbolDeserializer -import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.djvm.serialization.toSandboxAnyClass import net.corda.serialization.internal.amqp.* import org.apache.qpid.proton.amqp.Symbol import org.apache.qpid.proton.codec.Data import java.lang.reflect.Type -import java.util.function.BiFunction import java.util.function.Function class SandboxSymbolSerializer( classLoader: SandboxClassLoader, - executor: BiFunction, + taskFactory: Function>, basicInput: Function -) : CustomSerializer.Is(classLoader.loadClassForSandbox(Symbol::class.java)) { +) : CustomSerializer.Is(classLoader.toSandboxAnyClass(Symbol::class.java)) { private val transformer: Function init { - val transformTask = classLoader.loadClassForSandbox(SymbolDeserializer::class.java).newInstance() + val transformTask = classLoader.createTaskFor(taskFactory, SymbolDeserializer::class.java) @Suppress("unchecked_cast") - transformer = basicInput.andThen { input -> - executor.apply(transformTask, input) - } as Function + transformer = basicInput.andThen(transformTask) as Function } override val schemaForDocumentation: Schema = Schema(emptyList()) diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxToStringSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxToStringSerializer.kt index 765a406e1a..6482588ca7 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxToStringSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxToStringSerializer.kt @@ -3,31 +3,28 @@ package net.corda.djvm.serialization.serializers import net.corda.core.serialization.SerializationContext import net.corda.djvm.rewiring.SandboxClassLoader import net.corda.djvm.serialization.deserializers.CreateFromString -import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.djvm.serialization.toSandboxAnyClass import net.corda.serialization.internal.amqp.* import org.apache.qpid.proton.codec.Data import java.lang.reflect.Constructor import java.lang.reflect.Type import java.util.Collections.singleton -import java.util.function.BiFunction import java.util.function.Function class SandboxToStringSerializer( unsafeClass: Class<*>, classLoader: SandboxClassLoader, - executor: BiFunction, + taskFactory: Function>, basicInput: Function -) : CustomSerializer.Is(classLoader.loadClassForSandbox(unsafeClass)) { +) : CustomSerializer.Is(classLoader.toSandboxAnyClass(unsafeClass)) { private val creator: Function init { val stringClass = classLoader.loadClass("sandbox.java.lang.String") - val createTask = classLoader.loadClassForSandbox(CreateFromString::class.java) + val createTask = classLoader.toSandboxClass(CreateFromString::class.java) .getConstructor(Constructor::class.java) .newInstance(clazz.getConstructor(stringClass)) - creator = basicInput.andThen { input -> - executor.apply(createTask, input) - } + creator = basicInput.andThen(taskFactory.apply(createTask)) } override val deserializationAliases: Set> = singleton(unsafeClass) diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedByteSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedByteSerializer.kt index 30a208471a..df45ab0ea8 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedByteSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedByteSerializer.kt @@ -3,26 +3,20 @@ package net.corda.djvm.serialization.serializers import net.corda.core.serialization.SerializationContext import net.corda.djvm.rewiring.SandboxClassLoader import net.corda.djvm.serialization.deserializers.UnsignedByteDeserializer -import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.djvm.serialization.toSandboxAnyClass import net.corda.serialization.internal.amqp.* import org.apache.qpid.proton.amqp.UnsignedByte import org.apache.qpid.proton.codec.Data import java.lang.reflect.Type -import java.util.function.BiFunction import java.util.function.Function class SandboxUnsignedByteSerializer( classLoader: SandboxClassLoader, - executor: BiFunction -) : CustomSerializer.Is(classLoader.loadClassForSandbox(UnsignedByte::class.java)) { + taskFactory: Function> +) : CustomSerializer.Is(classLoader.toSandboxAnyClass(UnsignedByte::class.java)) { + @Suppress("unchecked_cast") private val transformer: Function - - init { - val transformTask = classLoader.loadClassForSandbox(UnsignedByteDeserializer::class.java).newInstance() - transformer = Function { inputs -> - executor.apply(transformTask, inputs) - } - } + = classLoader.createTaskFor(taskFactory, UnsignedByteDeserializer::class.java) as Function override val schemaForDocumentation: Schema = Schema(emptyList()) diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedIntegerSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedIntegerSerializer.kt index 15b7ee6bcb..73c0b7a071 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedIntegerSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedIntegerSerializer.kt @@ -3,26 +3,20 @@ package net.corda.djvm.serialization.serializers import net.corda.core.serialization.SerializationContext import net.corda.djvm.rewiring.SandboxClassLoader import net.corda.djvm.serialization.deserializers.UnsignedIntegerDeserializer -import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.djvm.serialization.toSandboxAnyClass import net.corda.serialization.internal.amqp.* import org.apache.qpid.proton.amqp.UnsignedInteger import org.apache.qpid.proton.codec.Data import java.lang.reflect.Type -import java.util.function.BiFunction import java.util.function.Function class SandboxUnsignedIntegerSerializer( classLoader: SandboxClassLoader, - executor: BiFunction -) : CustomSerializer.Is(classLoader.loadClassForSandbox(UnsignedInteger::class.java)) { + taskFactory: Function> +) : CustomSerializer.Is(classLoader.toSandboxAnyClass(UnsignedInteger::class.java)) { + @Suppress("unchecked_cast") private val transformer: Function - - init { - val transformTask = classLoader.loadClassForSandbox(UnsignedIntegerDeserializer::class.java).newInstance() - transformer = Function { inputs -> - executor.apply(transformTask, inputs) - } - } + = classLoader.createTaskFor(taskFactory, UnsignedIntegerDeserializer::class.java) as Function override val schemaForDocumentation: Schema = Schema(emptyList()) diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedLongSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedLongSerializer.kt index d63d7469da..66370c443c 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedLongSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedLongSerializer.kt @@ -3,27 +3,20 @@ package net.corda.djvm.serialization.serializers import net.corda.core.serialization.SerializationContext import net.corda.djvm.rewiring.SandboxClassLoader import net.corda.djvm.serialization.deserializers.UnsignedLongDeserializer -import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.djvm.serialization.toSandboxAnyClass import net.corda.serialization.internal.amqp.* import org.apache.qpid.proton.amqp.UnsignedLong import org.apache.qpid.proton.codec.Data import java.lang.reflect.Type -import java.util.Collections.singleton -import java.util.function.BiFunction import java.util.function.Function class SandboxUnsignedLongSerializer( classLoader: SandboxClassLoader, - executor: BiFunction -) : CustomSerializer.Is(classLoader.loadClassForSandbox(UnsignedLong::class.java)) { + taskFactory: Function> +) : CustomSerializer.Is(classLoader.toSandboxAnyClass(UnsignedLong::class.java)) { + @Suppress("unchecked_cast") private val transformer: Function - - init { - val transformTask = classLoader.loadClassForSandbox(UnsignedLongDeserializer::class.java).newInstance() - transformer = Function { inputs -> - executor.apply(transformTask, inputs) - } - } + = classLoader.createTaskFor(taskFactory, UnsignedLongDeserializer::class.java) as Function override val schemaForDocumentation: Schema = Schema(emptyList()) diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedShortSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedShortSerializer.kt index 6eaa91b9ef..d292531634 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedShortSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedShortSerializer.kt @@ -3,26 +3,20 @@ package net.corda.djvm.serialization.serializers import net.corda.core.serialization.SerializationContext import net.corda.djvm.rewiring.SandboxClassLoader import net.corda.djvm.serialization.deserializers.UnsignedShortDeserializer -import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.djvm.serialization.toSandboxAnyClass import net.corda.serialization.internal.amqp.* import org.apache.qpid.proton.amqp.UnsignedShort import org.apache.qpid.proton.codec.Data import java.lang.reflect.Type -import java.util.function.BiFunction import java.util.function.Function class SandboxUnsignedShortSerializer( classLoader: SandboxClassLoader, - executor: BiFunction -) : CustomSerializer.Is(classLoader.loadClassForSandbox(UnsignedShort::class.java)) { + taskFactory: Function> +) : CustomSerializer.Is(classLoader.toSandboxAnyClass(UnsignedShort::class.java)) { + @Suppress("unchecked_cast") private val transformer: Function - - init { - val transformTask = classLoader.loadClassForSandbox(UnsignedShortDeserializer::class.java).newInstance() - transformer = Function { inputs -> - executor.apply(transformTask, inputs) - } - } + = classLoader.createTaskFor(taskFactory, UnsignedShortDeserializer::class.java) as Function override val schemaForDocumentation: Schema = Schema(emptyList()) diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxX509CRLSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxX509CRLSerializer.kt index a9f4ae85a2..44ef1c4507 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxX509CRLSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxX509CRLSerializer.kt @@ -3,27 +3,21 @@ package net.corda.djvm.serialization.serializers import net.corda.core.serialization.SerializationContext import net.corda.djvm.rewiring.SandboxClassLoader import net.corda.djvm.serialization.deserializers.X509CRLDeserializer -import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.djvm.serialization.toSandboxAnyClass import net.corda.serialization.internal.amqp.* import org.apache.qpid.proton.codec.Data import java.lang.reflect.Type import java.security.cert.X509CRL import java.util.Collections.singleton -import java.util.function.BiFunction import java.util.function.Function class SandboxX509CRLSerializer( classLoader: SandboxClassLoader, - executor: BiFunction -) : CustomSerializer.Implements(classLoader.loadClassForSandbox(X509CRL::class.java)) { + taskFactory: Function> +) : CustomSerializer.Implements(classLoader.toSandboxAnyClass(X509CRL::class.java)) { + @Suppress("unchecked_cast") private val generator: Function - - init { - val generateTask = classLoader.loadClassForSandbox(X509CRLDeserializer::class.java).newInstance() - generator = Function { inputs -> - executor.apply(generateTask, inputs) - } - } + = classLoader.createTaskFor(taskFactory, X509CRLDeserializer::class.java) as Function override val schemaForDocumentation: Schema = Schema(emptyList()) diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxX509CertificateSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxX509CertificateSerializer.kt index ccb8d3c266..669403359f 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxX509CertificateSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxX509CertificateSerializer.kt @@ -3,27 +3,21 @@ package net.corda.djvm.serialization.serializers import net.corda.core.serialization.SerializationContext import net.corda.djvm.rewiring.SandboxClassLoader import net.corda.djvm.serialization.deserializers.X509CertificateDeserializer -import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.djvm.serialization.toSandboxAnyClass import net.corda.serialization.internal.amqp.* import org.apache.qpid.proton.codec.Data import java.lang.reflect.Type import java.security.cert.X509Certificate import java.util.Collections.singleton -import java.util.function.BiFunction import java.util.function.Function class SandboxX509CertificateSerializer( classLoader: SandboxClassLoader, - executor: BiFunction -) : CustomSerializer.Implements(classLoader.loadClassForSandbox(X509Certificate::class.java)) { + taskFactory: Function> +) : CustomSerializer.Implements(classLoader.toSandboxAnyClass(X509Certificate::class.java)) { + @Suppress("unchecked_cast") private val generator: Function - - init { - val generateTask = classLoader.loadClassForSandbox(X509CertificateDeserializer::class.java).newInstance() - generator = Function { inputs -> - executor.apply(generateTask, inputs) - } - } + = classLoader.createTaskFor(taskFactory, X509CertificateDeserializer::class.java) as Function override val schemaForDocumentation: Schema = Schema(emptyList()) diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxYearMonthSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxYearMonthSerializer.kt index 6c91ca9a03..3b31d33763 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxYearMonthSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxYearMonthSerializer.kt @@ -2,30 +2,30 @@ package net.corda.djvm.serialization.serializers import net.corda.djvm.rewiring.SandboxClassLoader import net.corda.djvm.serialization.deserializers.YearMonthDeserializer -import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.djvm.serialization.toSandboxAnyClass import net.corda.serialization.internal.amqp.CustomSerializer import net.corda.serialization.internal.amqp.SerializerFactory import net.corda.serialization.internal.amqp.custom.YearMonthSerializer.YearMonthProxy import java.time.YearMonth import java.util.Collections.singleton -import java.util.function.BiFunction +import java.util.function.Function class SandboxYearMonthSerializer( classLoader: SandboxClassLoader, - private val executor: BiFunction, + taskFactory: Function>, factory: SerializerFactory ) : CustomSerializer.Proxy( - clazz = classLoader.loadClassForSandbox(YearMonth::class.java), - proxyClass = classLoader.loadClassForSandbox(YearMonthProxy::class.java), + clazz = classLoader.toSandboxAnyClass(YearMonth::class.java), + proxyClass = classLoader.toSandboxAnyClass(YearMonthProxy::class.java), factory = factory ) { - private val task = classLoader.loadClassForSandbox(YearMonthDeserializer::class.java).newInstance() + private val task = classLoader.createTaskFor(taskFactory, YearMonthDeserializer::class.java) override val deserializationAliases: Set> = singleton(YearMonth::class.java) override fun toProxy(obj: Any): Any = abortReadOnly() override fun fromProxy(proxy: Any): Any { - return executor.apply(task, proxy)!! + return task.apply(proxy)!! } } diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxYearSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxYearSerializer.kt index 3d01eb1ff8..d2fef146bd 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxYearSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxYearSerializer.kt @@ -2,30 +2,30 @@ package net.corda.djvm.serialization.serializers import net.corda.djvm.rewiring.SandboxClassLoader import net.corda.djvm.serialization.deserializers.YearDeserializer -import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.djvm.serialization.toSandboxAnyClass import net.corda.serialization.internal.amqp.CustomSerializer import net.corda.serialization.internal.amqp.SerializerFactory import net.corda.serialization.internal.amqp.custom.YearSerializer.YearProxy import java.time.Year import java.util.Collections.singleton -import java.util.function.BiFunction +import java.util.function.Function class SandboxYearSerializer( classLoader: SandboxClassLoader, - private val executor: BiFunction, + taskFactory: Function>, factory: SerializerFactory ) : CustomSerializer.Proxy( - clazz = classLoader.loadClassForSandbox(Year::class.java), - proxyClass = classLoader.loadClassForSandbox(YearProxy::class.java), + clazz = classLoader.toSandboxAnyClass(Year::class.java), + proxyClass = classLoader.toSandboxAnyClass(YearProxy::class.java), factory = factory ) { - private val task = classLoader.loadClassForSandbox(YearDeserializer::class.java).newInstance() + private val task = classLoader.createTaskFor(taskFactory, YearDeserializer::class.java) override val deserializationAliases: Set> = singleton(Year::class.java) override fun toProxy(obj: Any): Any = abortReadOnly() override fun fromProxy(proxy: Any): Any { - return executor.apply(task, proxy)!! + return task.apply(proxy)!! } } diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxZoneIdSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxZoneIdSerializer.kt index 6ca73ee520..018e37fe27 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxZoneIdSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxZoneIdSerializer.kt @@ -2,24 +2,24 @@ package net.corda.djvm.serialization.serializers import net.corda.djvm.rewiring.SandboxClassLoader import net.corda.djvm.serialization.deserializers.ZoneIdDeserializer -import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.djvm.serialization.toSandboxAnyClass import net.corda.serialization.internal.amqp.CustomSerializer import net.corda.serialization.internal.amqp.SerializerFactory import net.corda.serialization.internal.amqp.custom.ZoneIdSerializer.ZoneIdProxy import java.time.ZoneId import java.util.Collections.singleton -import java.util.function.BiFunction +import java.util.function.Function class SandboxZoneIdSerializer( classLoader: SandboxClassLoader, - private val executor: BiFunction, + taskFactory: Function>, factory: SerializerFactory ) : CustomSerializer.Proxy( - clazz = classLoader.loadClassForSandbox(ZoneId::class.java), - proxyClass = classLoader.loadClassForSandbox(ZoneIdProxy::class.java), + clazz = classLoader.toSandboxAnyClass(ZoneId::class.java), + proxyClass = classLoader.toSandboxAnyClass(ZoneIdProxy::class.java), factory = factory ) { - private val task = classLoader.loadClassForSandbox(ZoneIdDeserializer::class.java).newInstance() + private val task = classLoader.createTaskFor(taskFactory, ZoneIdDeserializer::class.java) override val revealSubclassesInSchema: Boolean = true @@ -28,6 +28,6 @@ class SandboxZoneIdSerializer( override fun toProxy(obj: Any): Any = abortReadOnly() override fun fromProxy(proxy: Any): Any { - return executor.apply(task, proxy)!! + return task.apply(proxy)!! } } diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxZonedDateTimeSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxZonedDateTimeSerializer.kt index 5ef4f04f52..fa20800c1b 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxZonedDateTimeSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxZonedDateTimeSerializer.kt @@ -2,7 +2,7 @@ package net.corda.djvm.serialization.serializers import net.corda.djvm.rewiring.SandboxClassLoader import net.corda.djvm.serialization.deserializers.ZonedDateTimeDeserializer -import net.corda.djvm.serialization.loadClassForSandbox +import net.corda.djvm.serialization.toSandboxAnyClass import net.corda.serialization.internal.amqp.CustomSerializer import net.corda.serialization.internal.amqp.SerializerFactory import net.corda.serialization.internal.amqp.custom.ZonedDateTimeSerializer.ZonedDateTimeProxy @@ -11,28 +11,28 @@ import java.time.ZoneId import java.time.ZoneOffset import java.time.ZonedDateTime import java.util.Collections.singleton -import java.util.function.BiFunction +import java.util.function.Function class SandboxZonedDateTimeSerializer( classLoader: SandboxClassLoader, - executor: BiFunction, + taskFactory: Function>, factory: SerializerFactory ) : CustomSerializer.Proxy( - clazz = classLoader.loadClassForSandbox(ZonedDateTime::class.java), - proxyClass = classLoader.loadClassForSandbox(ZonedDateTimeProxy::class.java), + clazz = classLoader.toSandboxAnyClass(ZonedDateTime::class.java), + proxyClass = classLoader.toSandboxAnyClass(ZonedDateTimeProxy::class.java), factory = factory ) { - private val task = classLoader.loadClassForSandbox(ZonedDateTimeDeserializer::class.java).newInstance() - private val creator: BiFunction + private val task = classLoader.createTaskFor(taskFactory, ZonedDateTimeDeserializer::class.java) + private val creator: Function init { val createTask = clazz.getMethod( "createDJVM", - classLoader.loadClassForSandbox(LocalDateTime::class.java), - classLoader.loadClassForSandbox(ZoneOffset::class.java), - classLoader.loadClassForSandbox(ZoneId::class.java) + classLoader.toSandboxClass(LocalDateTime::class.java), + classLoader.toSandboxClass(ZoneOffset::class.java), + classLoader.toSandboxClass(ZoneId::class.java) ) - creator = executor.andThen { input -> + creator = task.andThen { input -> @Suppress("unchecked_cast") createTask(null, *(input as Array))!! } @@ -43,6 +43,6 @@ class SandboxZonedDateTimeSerializer( override fun toProxy(obj: Any): Any = abortReadOnly() override fun fromProxy(proxy: Any): Any { - return creator.apply(task, proxy)!! + return creator.apply(proxy)!! } } diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeBigDecimalTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeBigDecimalTest.kt index 58dc242a98..48864e8977 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeBigDecimalTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeBigDecimalTest.kt @@ -27,11 +27,9 @@ class DeserializeBigDecimalTest : TestBase(KOTLIN) { val sandboxBigInteger = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowBigDecimal::class.java).newInstance(), - sandboxBigInteger - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showBigDecimal = classLoader.createTaskFor(taskFactory, ShowBigDecimal::class.java) + val result = showBigDecimal.apply(sandboxBigInteger) ?: fail("Result cannot be null") assertEquals(ShowBigDecimal().apply(bigDecimal), result.toString()) assertEquals(SANDBOX_STRING, result::class.java.name) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeBigIntegerTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeBigIntegerTest.kt index b89e2443ee..52785f687e 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeBigIntegerTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeBigIntegerTest.kt @@ -27,11 +27,9 @@ class DeserializeBigIntegerTest : TestBase(KOTLIN) { val sandboxBigInteger = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowBigInteger::class.java).newInstance(), - sandboxBigInteger - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showBigInteger = classLoader.createTaskFor(taskFactory, ShowBigInteger::class.java) + val result = showBigInteger.apply(sandboxBigInteger) ?: fail("Result cannot be null") assertEquals(ShowBigInteger().apply(bigInteger), result.toString()) assertEquals(SANDBOX_STRING, result::class.java.name) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeBitSetTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeBitSetTest.kt index 5b59a1fe4f..5ca8297121 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeBitSetTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeBitSetTest.kt @@ -22,11 +22,9 @@ class DeserializeBitSetTest : TestBase(KOTLIN) { val sandboxBitSet = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowBitSet::class.java).newInstance(), - sandboxBitSet - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showBitSet = classLoader.createTaskFor(taskFactory, ShowBitSet::class.java) + val result = showBitSet.apply(sandboxBitSet) ?: fail("Result cannot be null") assertEquals(bitSet.toString(), result.toString()) assertEquals(SANDBOX_STRING, result::class.java.name) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeCertificatesTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeCertificatesTest.kt index ce8b0b33d5..95e6d48b47 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeCertificatesTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeCertificatesTest.kt @@ -54,11 +54,9 @@ class DeserializeCertificatesTest : TestBase(KOTLIN) { val sandboxCertPath = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowCertPath::class.java).newInstance(), - sandboxCertPath - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showCertPath = classLoader.createTaskFor(taskFactory, ShowCertPath::class.java) + val result = showCertPath.apply(sandboxCertPath) ?: fail("Result cannot be null") assertEquals(ShowCertPath().apply(certPath), localise(result.toString())) assertThat(result::class.java.name).startsWith("sandbox.") @@ -80,11 +78,9 @@ class DeserializeCertificatesTest : TestBase(KOTLIN) { val sandboxCertificate = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowCertificate::class.java).newInstance(), - sandboxCertificate - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showCertificate = classLoader.createTaskFor(taskFactory, ShowCertificate::class.java) + val result = showCertificate.apply(sandboxCertificate) ?: fail("Result cannot be null") assertEquals(ShowCertificate().apply(certificate), localise(result.toString())) assertThat(result::class.java.name).startsWith("sandbox.") @@ -116,11 +112,9 @@ class DeserializeCertificatesTest : TestBase(KOTLIN) { val sandboxCRL = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowCRL::class.java).newInstance(), - sandboxCRL - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showCRL = classLoader.createTaskFor(taskFactory, ShowCRL::class.java) + val result = showCRL.apply(sandboxCRL) ?: fail("Result cannot be null") assertEquals(ShowCRL().apply(crl), localise(result.toString())) assertThat(result::class.java.name).startsWith("sandbox.") diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeClassTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeClassTest.kt index 13b7a4f30e..085301f7f6 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeClassTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeClassTest.kt @@ -25,11 +25,9 @@ class DeserializeClassTest : TestBase(KOTLIN) { val sandboxInstant = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowClass::class.java).newInstance(), - sandboxInstant - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showClass = classLoader.createTaskFor(taskFactory, ShowClass::class.java) + val result = showClass.apply(sandboxInstant) ?: fail("Result cannot be null") assertEquals("sandbox.${myClass.name}", result.toString()) assertEquals(SANDBOX_STRING, result::class.java.name) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeCollectionsTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeCollectionsTest.kt index 2548ad88d5..3b109550a4 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeCollectionsTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeCollectionsTest.kt @@ -25,11 +25,9 @@ class DeserializeCollectionsTest : TestBase(KOTLIN) { val sandboxList = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowStringList::class.java).newInstance(), - sandboxList - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showStringList = classLoader.createTaskFor(taskFactory, ShowStringList::class.java) + val result = showStringList.apply(sandboxList) ?: fail("Result cannot be null") assertEquals(stringList.lines.joinToString(), result.toString()) assertEquals("Hello, World, !", result.toString()) @@ -52,11 +50,9 @@ class DeserializeCollectionsTest : TestBase(KOTLIN) { val sandboxSet = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowIntegerSet::class.java).newInstance(), - sandboxSet - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showIntegerSet = classLoader.createTaskFor(taskFactory, ShowIntegerSet::class.java) + val result = showIntegerSet.apply(sandboxSet) ?: fail("Result cannot be null") assertEquals(integerSet.numbers.joinToString(), result.toString()) assertEquals("10, 3, 15, 2", result.toString()) @@ -79,11 +75,9 @@ class DeserializeCollectionsTest : TestBase(KOTLIN) { val sandboxSet = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowIntegerSortedSet::class.java).newInstance(), - sandboxSet - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showIntegerSortedSet = classLoader.createTaskFor(taskFactory, ShowIntegerSortedSet::class.java) + val result = showIntegerSortedSet.apply(sandboxSet) ?: fail("Result cannot be null") assertEquals(integerSortedSet.numbers.joinToString(), result.toString()) assertEquals("2, 3, 10, 15, 1000", result.toString()) @@ -106,11 +100,9 @@ class DeserializeCollectionsTest : TestBase(KOTLIN) { val sandboxSet = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowLongNavigableSet::class.java).newInstance(), - sandboxSet - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showLongNavigableSet = classLoader.createTaskFor(taskFactory, ShowLongNavigableSet::class.java) + val result = showLongNavigableSet.apply(sandboxSet) ?: fail("Result cannot be null") assertEquals(longNavigableSet.numbers.joinToString(), result.toString()) assertEquals("2, 3, 10, 15, 1000, 99955", result.toString()) @@ -133,11 +125,9 @@ class DeserializeCollectionsTest : TestBase(KOTLIN) { val sandboxCollection = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowShortCollection::class.java).newInstance(), - sandboxCollection - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showShortCollection = classLoader.createTaskFor(taskFactory, ShowShortCollection::class.java) + val result = showShortCollection.apply(sandboxCollection) ?: fail("Result cannot be null") assertEquals(shortCollection.numbers.joinToString(), result.toString()) assertEquals("10, 200, 3000", result.toString()) @@ -160,11 +150,9 @@ class DeserializeCollectionsTest : TestBase(KOTLIN) { val sandboxSet = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowNonEmptyStringSet::class.java).newInstance(), - sandboxSet - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showNonEmptyStringSet = classLoader.createTaskFor(taskFactory, ShowNonEmptyStringSet::class.java) + val result = showNonEmptyStringSet.apply(sandboxSet) ?: fail("Result cannot be null") assertEquals(nonEmptyStrings.lines.joinToString(), result.toString()) assertEquals("Hello, World, !", result.toString()) @@ -187,11 +175,9 @@ class DeserializeCollectionsTest : TestBase(KOTLIN) { val sandboxSet = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowHasEnumSet::class.java).newInstance(), - sandboxSet - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showHasEnumSet = classLoader.createTaskFor(taskFactory, ShowHasEnumSet::class.java) + val result = showHasEnumSet.apply(sandboxSet) ?: fail("Result cannot be null") assertEquals(enumSet.values.toString(), result.toString()) assertEquals("[DOH]", result.toString()) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeCurrencyTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeCurrencyTest.kt index aa5870951e..a30b088e49 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeCurrencyTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeCurrencyTest.kt @@ -23,11 +23,9 @@ class DeserializeCurrencyTest : TestBase(KOTLIN) { val sandboxCurrency = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowCurrency::class.java).newInstance(), - sandboxCurrency - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showCurrency = classLoader.createTaskFor(taskFactory, ShowCurrency::class.java) + val result = showCurrency.apply(sandboxCurrency) ?: fail("Result cannot be null") assertEquals(ShowCurrency().apply(currency), result.toString()) assertEquals(SANDBOX_STRING, result::class.java.name) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeEnumSetTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeEnumSetTest.kt index 2dba16c4ed..6f70ce5285 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeEnumSetTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeEnumSetTest.kt @@ -25,11 +25,9 @@ class DeserializeEnumSetTest : TestBase(KOTLIN) { val sandboxEnumSet = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowEnumSet::class.java).newInstance(), - sandboxEnumSet - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showEnumSet = classLoader.createTaskFor(taskFactory, ShowEnumSet::class.java) + val result = showEnumSet.apply(sandboxEnumSet) ?: fail("Result cannot be null") assertEquals(ShowEnumSet().apply(enumSet), result.toString()) assertEquals("EnumSet: [$value]'", result.toString()) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeEnumTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeEnumTest.kt index 2ff7d78e39..4d4784a5c2 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeEnumTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeEnumTest.kt @@ -24,11 +24,9 @@ class DeserializeEnumTest : TestBase(KOTLIN) { val sandboxExample = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowExampleData::class.java).newInstance(), - sandboxExample - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showExampleData = classLoader.createTaskFor(taskFactory, ShowExampleData::class.java) + val result = showExampleData.apply(sandboxExample) ?: fail("Result cannot be null") assertEquals(ShowExampleData().apply(example), result.toString()) assertEquals("Example: name='${value.name}', ordinal='${value.ordinal}'", result.toString()) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeGenericsTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeGenericsTest.kt index 5e887e1b4b..815351467c 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeGenericsTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeGenericsTest.kt @@ -24,11 +24,9 @@ class DeserializeGenericsTest : TestBase(KOTLIN) { val sandboxWrapper = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowGenericWrapper::class.java).newInstance(), - sandboxWrapper - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showGenericWrapper = classLoader.createTaskFor(taskFactory, ShowGenericWrapper::class.java) + val result = showGenericWrapper.apply(sandboxWrapper) ?: fail("Result cannot be null") assertEquals("Hello World!", result.toString()) assertEquals(SANDBOX_STRING, result::class.java.name) @@ -54,11 +52,9 @@ class DeserializeGenericsTest : TestBase(KOTLIN) { val sandboxWrapped = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowConcreteWrapper::class.java).newInstance(), - sandboxWrapped - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showConcreteWrapper = classLoader.createTaskFor(taskFactory, ShowConcreteWrapper::class.java) + val result = showConcreteWrapper.apply(sandboxWrapped) ?: fail("Result cannot be null") assertEquals("Concrete: first='Hello World', second='!'", result.toString()) } diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeInputStreamTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeInputStreamTest.kt index 84cdd80712..d8aa937089 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeInputStreamTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeInputStreamTest.kt @@ -26,11 +26,9 @@ class DeserializeInputStreamTest : TestBase(KOTLIN) { val sandboxStream = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowInputStream::class.java).newInstance(), - sandboxStream - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showInputStream = classLoader.createTaskFor(taskFactory, ShowInputStream::class.java) + val result = showInputStream.apply(sandboxStream) ?: fail("Result cannot be null") assertEquals(String(MESSAGE.byteInputStream().readFully()), result.toString()) assertEquals(SANDBOX_STRING, result::class.java.name) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeInstantTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeInstantTest.kt index 2316de6dfa..b634aafc60 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeInstantTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeInstantTest.kt @@ -22,11 +22,9 @@ class DeserializeInstantTest : TestBase(KOTLIN) { val sandboxInstant = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowInstant::class.java).newInstance(), - sandboxInstant - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showInstant = classLoader.createTaskFor(taskFactory, ShowInstant::class.java) + val result = showInstant.apply(sandboxInstant) ?: fail("Result cannot be null") assertEquals(instant.toString(), result.toString()) assertEquals(SANDBOX_STRING, result::class.java.name) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeJavaWithMultipleConstructorsTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeJavaWithMultipleConstructorsTest.kt index 719d28a03e..7fc4d458c4 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeJavaWithMultipleConstructorsTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeJavaWithMultipleConstructorsTest.kt @@ -22,11 +22,9 @@ class DeserializeJavaWithMultipleConstructorsTest : TestBase(KOTLIN) { val sandboxData = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowMultiData::class.java).newInstance(), - sandboxData - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showMultiData = classLoader.createTaskFor(taskFactory, ShowMultiData::class.java) + val result = showMultiData.apply(sandboxData) ?: fail("Result cannot be null") assertThat(result.toString()) .isEqualTo("MultiConstructor[message='Hello World', bigNumber=9223372036854775807, tag=!]") diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeLocalDateTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeLocalDateTest.kt index 007ca86548..4d11d4b936 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeLocalDateTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeLocalDateTest.kt @@ -22,11 +22,9 @@ class DeserializeLocalDateTest : TestBase(KOTLIN) { val sandboxDate = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowLocalDate::class.java).newInstance(), - sandboxDate - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showLocalDate = classLoader.createTaskFor(taskFactory, ShowLocalDate::class.java) + val result = showLocalDate.apply(sandboxDate) ?: fail("Result cannot be null") assertEquals(date.toString(), result.toString()) assertEquals(SANDBOX_STRING, result::class.java.name) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeLocalDateTimeTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeLocalDateTimeTest.kt index 1dd9debfbe..69f48a4611 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeLocalDateTimeTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeLocalDateTimeTest.kt @@ -22,11 +22,9 @@ class DeserializeLocalDateTimeTest : TestBase(KOTLIN) { val sandboxDateTime = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowLocalDateTime::class.java).newInstance(), - sandboxDateTime - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showLocalDateTime = classLoader.createTaskFor(taskFactory, ShowLocalDateTime::class.java) + val result = showLocalDateTime.apply( sandboxDateTime) ?: fail("Result cannot be null") assertEquals(dateTime.toString(), result.toString()) assertEquals(SANDBOX_STRING, result::class.java.name) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeLocalTimeTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeLocalTimeTest.kt index 2bfb4c2956..21360d3606 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeLocalTimeTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeLocalTimeTest.kt @@ -22,11 +22,9 @@ class DeserializeLocalTimeTest : TestBase(KOTLIN) { val sandboxTime = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowLocalTime::class.java).newInstance(), - sandboxTime - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showLocalTime = classLoader.createTaskFor(taskFactory, ShowLocalTime::class.java) + val result = showLocalTime.apply(sandboxTime) ?: fail("Result cannot be null") assertEquals(time.toString(), result.toString()) assertEquals(SANDBOX_STRING, result::class.java.name) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeMapsTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeMapsTest.kt index b4f8d692ef..e680d4d471 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeMapsTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeMapsTest.kt @@ -23,11 +23,9 @@ class DeserializeMapsTest : TestBase(KOTLIN) { val sandboxMap = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowStringMap::class.java).newInstance(), - sandboxMap - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showStringMap = classLoader.createTaskFor(taskFactory, ShowStringMap::class.java) + val result = showStringMap.apply(sandboxMap) ?: fail("Result cannot be null") assertEquals(stringMap.values.entries.joinToString(), result.toString()) assertEquals("Open=Hello World, Close=Goodbye, Cruel World", result.toString()) @@ -54,11 +52,9 @@ class DeserializeMapsTest : TestBase(KOTLIN) { val sandboxMap = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowStringSortedMap::class.java).newInstance(), - sandboxMap - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showStringSortedMap = classLoader.createTaskFor(taskFactory, ShowStringSortedMap::class.java) + val result = showStringSortedMap.apply(sandboxMap) ?: fail("Result cannot be null") assertEquals(sortedMap.values.entries.joinToString(), result.toString()) assertEquals("10=Hello World, 50=Having Fun!, 100=Goodbye, Cruel World", result.toString()) @@ -85,11 +81,9 @@ class DeserializeMapsTest : TestBase(KOTLIN) { val sandboxMap = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowStringNavigableMap::class.java).newInstance(), - sandboxMap - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showStringNavigableMap = classLoader.createTaskFor(taskFactory, ShowStringNavigableMap::class.java) + val result = showStringNavigableMap.apply(sandboxMap) ?: fail("Result cannot be null") assertEquals(navigableMap.values.entries.joinToString(), result.toString()) assertEquals("1000=Hello World, 5000=Having Fun!, 10000=Goodbye, Cruel World", result.toString()) @@ -116,11 +110,9 @@ class DeserializeMapsTest : TestBase(KOTLIN) { val sandboxMap = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowStringLinkedHashMap::class.java).newInstance(), - sandboxMap - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showStringLinkedHashMap = classLoader.createTaskFor(taskFactory, ShowStringLinkedHashMap::class.java) + val result = showStringLinkedHashMap.apply(sandboxMap) ?: fail("Result cannot be null") assertEquals(linkedHashMap.values.entries.joinToString(), result.toString()) assertEquals("Close=Goodbye, Cruel World, Open=Hello World, During=Having Fun!", result.toString()) @@ -147,11 +139,9 @@ class DeserializeMapsTest : TestBase(KOTLIN) { val sandboxMap = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowStringTreeMap::class.java).newInstance(), - sandboxMap - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showStringTreeMap = classLoader.createTaskFor(taskFactory, ShowStringTreeMap::class.java) + val result = showStringTreeMap.apply(sandboxMap) ?: fail("Result cannot be null") assertEquals(treeMap.values.entries.joinToString(), result.toString()) assertEquals("1000=Hello World, 5000=Having Fun!, 10000=Goodbye, Cruel World", result.toString()) @@ -177,11 +167,9 @@ class DeserializeMapsTest : TestBase(KOTLIN) { val sandboxMap = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowEnumMap::class.java).newInstance(), - sandboxMap - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showEnumMap = classLoader.createTaskFor(taskFactory, ShowEnumMap::class.java) + val result = showEnumMap.apply(sandboxMap) ?: fail("Result cannot be null") assertEquals(enumMap.toString(), result.toString()) assertEquals("{ONE=One!, TWO=Two!}", result.toString()) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeMonthDayTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeMonthDayTest.kt index b9e7fac533..7f0a19028c 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeMonthDayTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeMonthDayTest.kt @@ -22,11 +22,9 @@ class DeserializeMonthDayTest : TestBase(KOTLIN) { val sandboxMonthDay = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowMonthDay::class.java).newInstance(), - sandboxMonthDay - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showMonthDay = classLoader.createTaskFor(taskFactory, ShowMonthDay::class.java) + val result = showMonthDay.apply(sandboxMonthDay) ?: fail("Result cannot be null") assertEquals(monthDay.toString(), result.toString()) assertEquals(SANDBOX_STRING, result::class.java.name) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeObjectArraysTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeObjectArraysTest.kt index b1b1a74928..47cd38f17b 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeObjectArraysTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeObjectArraysTest.kt @@ -24,11 +24,9 @@ class DeserializeObjectArraysTest : TestBase(KOTLIN) { val sandboxArray = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowStringArray::class.java).newInstance(), - sandboxArray - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showStringArray = classLoader.createTaskFor(taskFactory, ShowStringArray::class.java) + val result = showStringArray.apply(sandboxArray) ?: fail("Result cannot be null") assertEquals(SANDBOX_STRING, result::class.java.name) assertEquals("Hello, World, !", result.toString()) @@ -52,11 +50,9 @@ class DeserializeObjectArraysTest : TestBase(KOTLIN) { val sandboxArray = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowCharacterArray::class.java).newInstance(), - sandboxArray - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showCharacterArray = classLoader.createTaskFor(taskFactory, ShowCharacterArray::class.java) + val result = showCharacterArray.apply(sandboxArray) ?: fail("Result cannot be null") assertEquals(SANDBOX_STRING, result::class.java.name) assertEquals("Hello!", result.toString()) @@ -79,11 +75,9 @@ class DeserializeObjectArraysTest : TestBase(KOTLIN) { val sandboxArray = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowLongArray::class.java).newInstance(), - sandboxArray - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showLongArray = classLoader.createTaskFor(taskFactory, ShowLongArray::class.java) + val result = showLongArray.apply(sandboxArray) ?: fail("Result cannot be null") assertEquals("sandbox.java.lang.Long", result::class.java.name) assertEquals("15000", result.toString()) @@ -106,11 +100,9 @@ class DeserializeObjectArraysTest : TestBase(KOTLIN) { val sandboxArray = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowIntegerArray::class.java).newInstance(), - sandboxArray - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showIntegerArray = classLoader.createTaskFor(taskFactory, ShowIntegerArray::class.java) + val result = showIntegerArray.apply(sandboxArray) ?: fail("Result cannot be null") assertEquals("sandbox.java.lang.Integer", result::class.java.name) assertEquals("1500", result.toString()) @@ -133,11 +125,9 @@ class DeserializeObjectArraysTest : TestBase(KOTLIN) { val sandboxArray = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowShortArray::class.java).newInstance(), - sandboxArray - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showShortArray = classLoader.createTaskFor(taskFactory, ShowShortArray::class.java) + val result = showShortArray.apply(sandboxArray) ?: fail("Result cannot be null") assertEquals("sandbox.java.lang.Integer", result::class.java.name) assertEquals("1500", result.toString()) @@ -160,11 +150,9 @@ class DeserializeObjectArraysTest : TestBase(KOTLIN) { val sandboxArray = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowByteArray::class.java).newInstance(), - sandboxArray - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showByteArray = classLoader.createTaskFor(taskFactory, ShowByteArray::class.java) + val result = showByteArray.apply(sandboxArray) ?: fail("Result cannot be null") assertEquals("sandbox.java.lang.Integer", result::class.java.name) assertEquals("150", result.toString()) @@ -187,11 +175,9 @@ class DeserializeObjectArraysTest : TestBase(KOTLIN) { val sandboxArray = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowDoubleArray::class.java).newInstance(), - sandboxArray - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showDoubleArray = classLoader.createTaskFor(taskFactory, ShowDoubleArray::class.java) + val result = showDoubleArray.apply(sandboxArray) ?: fail("Result cannot be null") assertEquals("sandbox.java.lang.Double", result::class.java.name) assertEquals("15000.0", result.toString()) @@ -214,11 +200,9 @@ class DeserializeObjectArraysTest : TestBase(KOTLIN) { val sandboxArray = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowFloatArray::class.java).newInstance(), - sandboxArray - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showFloatArray = classLoader.createTaskFor(taskFactory, ShowFloatArray::class.java) + val result = showFloatArray.apply(sandboxArray) ?: fail("Result cannot be null") assertEquals("sandbox.java.lang.Float", result::class.java.name) assertEquals("150.0", result.toString()) @@ -241,11 +225,9 @@ class DeserializeObjectArraysTest : TestBase(KOTLIN) { val sandboxArray = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowBooleanArray::class.java).newInstance(), - sandboxArray - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showBooleanArray = classLoader.createTaskFor(taskFactory, ShowBooleanArray::class.java) + val result = showBooleanArray.apply(sandboxArray) ?: fail("Result cannot be null") assertEquals("sandbox.java.lang.Boolean", result::class.java.name) assertEquals("true", result.toString()) @@ -269,11 +251,9 @@ class DeserializeObjectArraysTest : TestBase(KOTLIN) { val sandboxArray = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowUUIDArray::class.java).newInstance(), - sandboxArray - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showUUIDArray = classLoader.createTaskFor(taskFactory, ShowUUIDArray::class.java) + val result = showUUIDArray.apply(sandboxArray) ?: fail("Result cannot be null") assertEquals(SANDBOX_STRING, result::class.java.name) assertEquals(uuid.toString(), result.toString()) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeOffsetDateTimeTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeOffsetDateTimeTest.kt index cfc004522e..c17b2824d5 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeOffsetDateTimeTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeOffsetDateTimeTest.kt @@ -22,11 +22,9 @@ class DeserializeOffsetDateTimeTest : TestBase(KOTLIN) { val sandboxDateTime = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowOffsetDateTime::class.java).newInstance(), - sandboxDateTime - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showOffsetDateTime = classLoader.createTaskFor(taskFactory, ShowOffsetDateTime::class.java) + val result = showOffsetDateTime.apply(sandboxDateTime) ?: fail("Result cannot be null") assertEquals(dateTime.toString(), result.toString()) assertEquals(SANDBOX_STRING, result::class.java.name) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeOffsetTimeTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeOffsetTimeTest.kt index a9eaad89f4..38b197f227 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeOffsetTimeTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeOffsetTimeTest.kt @@ -22,11 +22,9 @@ class DeserializeOffsetTimeTest : TestBase(KOTLIN) { val sandboxTime = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowOffsetTime::class.java).newInstance(), - sandboxTime - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showOffsetTime = classLoader.createTaskFor(taskFactory, ShowOffsetTime::class.java) + val result = showOffsetTime.apply(sandboxTime) ?: fail("Result cannot be null") assertEquals(time.toString(), result.toString()) assertEquals(SANDBOX_STRING, result::class.java.name) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeOpaqueBytesSubSequenceTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeOpaqueBytesSubSequenceTest.kt index 519a86e6e3..a91bcba6ca 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeOpaqueBytesSubSequenceTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeOpaqueBytesSubSequenceTest.kt @@ -31,11 +31,9 @@ class DeserializeOpaqueBytesSubSequenceTest : TestBase(KOTLIN) { val sandboxBytes = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowOpaqueBytesSubSequence::class.java).newInstance(), - sandboxBytes - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showOpaqueBytesSubSequence = classLoader.createTaskFor(taskFactory, ShowOpaqueBytesSubSequence::class.java) + val result = showOpaqueBytesSubSequence.apply(sandboxBytes) ?: fail("Result cannot be null") assertEquals(MESSAGE.substring(OFFSET), String(result as ByteArray)) assertEquals(String(subSequence.copyBytes()), String(result)) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeOptionalTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeOptionalTest.kt index 8104f282ab..da085d6299 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeOptionalTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeOptionalTest.kt @@ -22,11 +22,9 @@ class DeserializeOptionalTest : TestBase(KOTLIN) { val sandboxOptional = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowOptional::class.java).newInstance(), - sandboxOptional - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showOptional = classLoader.createTaskFor(taskFactory, ShowOptional::class.java) + val result = showOptional.apply(sandboxOptional) ?: fail("Result cannot be null") assertEquals("Optional -> Optional[Hello World!]", result.toString()) assertEquals(SANDBOX_STRING, result::class.java.name) @@ -43,11 +41,9 @@ class DeserializeOptionalTest : TestBase(KOTLIN) { val sandboxOptional = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowOptional::class.java).newInstance(), - sandboxOptional - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showOptional = classLoader.createTaskFor(taskFactory, ShowOptional::class.java) + val result = showOptional.apply(sandboxOptional) ?: fail("Result cannot be null") assertEquals("Optional -> Optional.empty", result.toString()) assertEquals(SANDBOX_STRING, result::class.java.name) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializePeriodTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializePeriodTest.kt index 2784dbd8aa..cdd95affa6 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializePeriodTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializePeriodTest.kt @@ -22,11 +22,9 @@ class DeserializePeriodTest : TestBase(KOTLIN) { val sandboxPeriod = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowPeriod::class.java).newInstance(), - sandboxPeriod - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showPeriod = classLoader.createTaskFor(taskFactory, ShowPeriod::class.java) + val result = showPeriod.apply(sandboxPeriod) ?: fail("Result cannot be null") assertEquals(period.toString(), result.toString()) assertEquals(SANDBOX_STRING, result::class.java.name) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializePrimitiveArraysTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializePrimitiveArraysTest.kt index 4cb3b4b30a..3187763f37 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializePrimitiveArraysTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializePrimitiveArraysTest.kt @@ -23,11 +23,9 @@ class DeserializePrimitiveArraysTest : TestBase(KOTLIN) { val sandboxArray = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowCharArray::class.java).newInstance(), - sandboxArray - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showCharArray = classLoader.createTaskFor(taskFactory, ShowCharArray::class.java) + val result = showCharArray.apply(sandboxArray) ?: fail("Result cannot be null") assertEquals(SANDBOX_STRING, result::class.java.name) assertEquals("Hello!", result.toString()) @@ -50,11 +48,9 @@ class DeserializePrimitiveArraysTest : TestBase(KOTLIN) { val sandboxArray = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowIntegerArray::class.java).newInstance(), - sandboxArray - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showIntegerArray = classLoader.createTaskFor(taskFactory, ShowIntegerArray::class.java) + val result = showIntegerArray.apply(sandboxArray) ?: fail("Result cannot be null") assertEquals("sandbox.java.lang.Integer", result::class.java.name) assertEquals("1500", result.toString()) @@ -77,11 +73,9 @@ class DeserializePrimitiveArraysTest : TestBase(KOTLIN) { val sandboxArray = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowLongArray::class.java).newInstance(), - sandboxArray - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showLongArray = classLoader.createTaskFor(taskFactory, ShowLongArray::class.java) + val result = showLongArray.apply(sandboxArray) ?: fail("Result cannot be null") assertEquals("sandbox.java.lang.Long", result::class.java.name) assertEquals("15000", result.toString()) @@ -104,11 +98,9 @@ class DeserializePrimitiveArraysTest : TestBase(KOTLIN) { val sandboxArray = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowShortArray::class.java).newInstance(), - sandboxArray - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showShortArray = classLoader.createTaskFor(taskFactory, ShowShortArray::class.java) + val result = showShortArray.apply(sandboxArray) ?: fail("Result cannot be null") assertEquals("sandbox.java.lang.Integer", result::class.java.name) assertEquals("1500", result.toString()) @@ -131,11 +123,9 @@ class DeserializePrimitiveArraysTest : TestBase(KOTLIN) { val sandboxArray = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowByteArray::class.java).newInstance(), - sandboxArray - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showByteArray = classLoader.createTaskFor(taskFactory, ShowByteArray::class.java) + val result = showByteArray.apply(sandboxArray) ?: fail("Result cannot be null") assertEquals("sandbox.java.lang.Integer", result::class.java.name) assertEquals("150", result.toString()) @@ -158,11 +148,9 @@ class DeserializePrimitiveArraysTest : TestBase(KOTLIN) { val sandboxArray = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowBooleanArray::class.java).newInstance(), - sandboxArray - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showBooleanArray = classLoader.createTaskFor(taskFactory, ShowBooleanArray::class.java) + val result = showBooleanArray.apply(sandboxArray) ?: fail("Result cannot be null") assertEquals("sandbox.java.lang.Boolean", result::class.java.name) assertEquals("true", result.toString()) @@ -185,11 +173,9 @@ class DeserializePrimitiveArraysTest : TestBase(KOTLIN) { val sandboxArray = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowDoubleArray::class.java).newInstance(), - sandboxArray - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showDoubleArray = classLoader.createTaskFor(taskFactory, ShowDoubleArray::class.java) + val result = showDoubleArray.apply(sandboxArray) ?: fail("Result cannot be null") assertEquals("sandbox.java.lang.Double", result::class.java.name) assertEquals("15000.0", result.toString()) @@ -212,11 +198,9 @@ class DeserializePrimitiveArraysTest : TestBase(KOTLIN) { val sandboxArray = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowFloatArray::class.java).newInstance(), - sandboxArray - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showFloatArray = classLoader.createTaskFor(taskFactory, ShowFloatArray::class.java) + val result = showFloatArray.apply(sandboxArray) ?: fail("Result cannot be null") assertEquals("sandbox.java.lang.Float", result::class.java.name) assertEquals("1500.0", result.toString()) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeProtonJTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeProtonJTest.kt index 2de052b5d1..5b3be55607 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeProtonJTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeProtonJTest.kt @@ -24,11 +24,9 @@ class DeserializeProtonJTest : TestBase(KOTLIN) { val sandboxProtonJ = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowUnsignedLong::class.java).newInstance(), - sandboxProtonJ - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showUnsignedLong = classLoader.createTaskFor(taskFactory, ShowUnsignedLong::class.java) + val result = showUnsignedLong.apply(sandboxProtonJ) ?: fail("Result cannot be null") assertEquals(protonJ.number.toString(), result.toString()) assertEquals(SANDBOX_STRING, result::class.java.name) @@ -51,11 +49,9 @@ class DeserializeProtonJTest : TestBase(KOTLIN) { val sandboxProtonJ = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowUnsignedInteger::class.java).newInstance(), - sandboxProtonJ - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showUnsignedInteger = classLoader.createTaskFor(taskFactory, ShowUnsignedInteger::class.java) + val result = showUnsignedInteger.apply(sandboxProtonJ) ?: fail("Result cannot be null") assertEquals(protonJ.number.toString(), result.toString()) assertEquals(SANDBOX_STRING, result::class.java.name) @@ -78,11 +74,9 @@ class DeserializeProtonJTest : TestBase(KOTLIN) { val sandboxProtonJ = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowUnsignedShort::class.java).newInstance(), - sandboxProtonJ - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showUnsignedShort = classLoader.createTaskFor(taskFactory, ShowUnsignedShort::class.java) + val result = showUnsignedShort.apply(sandboxProtonJ) ?: fail("Result cannot be null") assertEquals(protonJ.number.toString(), result.toString()) assertEquals(SANDBOX_STRING, result::class.java.name) @@ -105,11 +99,9 @@ class DeserializeProtonJTest : TestBase(KOTLIN) { val sandboxProtonJ = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowUnsignedByte::class.java).newInstance(), - sandboxProtonJ - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showUnsignedByte = classLoader.createTaskFor(taskFactory, ShowUnsignedByte::class.java) + val result = showUnsignedByte.apply(sandboxProtonJ) ?: fail("Result cannot be null") assertEquals(protonJ.number.toString(), result.toString()) assertEquals(SANDBOX_STRING, result::class.java.name) @@ -132,11 +124,9 @@ class DeserializeProtonJTest : TestBase(KOTLIN) { val sandboxProtonJ = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowDecimal128::class.java).newInstance(), - sandboxProtonJ - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showDecimal128 = classLoader.createTaskFor(taskFactory, ShowDecimal128::class.java) + val result = showDecimal128.apply(sandboxProtonJ) ?: fail("Result cannot be null") assertThat(result) .isEqualTo(protonJ.number.let { longArrayOf(it.mostSignificantBits, it.leastSignificantBits) }) @@ -159,11 +149,9 @@ class DeserializeProtonJTest : TestBase(KOTLIN) { val sandboxProtonJ = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowDecimal64::class.java).newInstance(), - sandboxProtonJ - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showDecimal64 = classLoader.createTaskFor(taskFactory, ShowDecimal64::class.java) + val result = showDecimal64.apply(sandboxProtonJ) ?: fail("Result cannot be null") assertEquals(protonJ.number.bits.toString(), result.toString()) } @@ -185,11 +173,9 @@ class DeserializeProtonJTest : TestBase(KOTLIN) { val sandboxProtonJ = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowDecimal32::class.java).newInstance(), - sandboxProtonJ - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showDecimal32 = classLoader.createTaskFor(taskFactory, ShowDecimal32::class.java) + val result = showDecimal32.apply(sandboxProtonJ) ?: fail("Result cannot be null") assertEquals(protonJ.number.bits.toString(), result.toString()) } @@ -211,11 +197,9 @@ class DeserializeProtonJTest : TestBase(KOTLIN) { val sandboxProtonJ = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowSymbol::class.java).newInstance(), - sandboxProtonJ - ) ?: fail("Result cannot be null") + val executor = classLoader.createRawTaskFactory() + val taskFactory = classLoader.createTaskFor(executor, ShowSymbol::class.java) + val result = taskFactory.apply(sandboxProtonJ) ?: fail("Result cannot be null") assertEquals(protonJ.symbol.toString(), result.toString()) assertEquals(SANDBOX_STRING, result::class.java.name) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializePublicKeyTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializePublicKeyTest.kt index e6834d0a39..633d179be6 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializePublicKeyTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializePublicKeyTest.kt @@ -43,11 +43,9 @@ class DeserializePublicKeyTest : TestBase(KOTLIN) { val sandboxKey = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowPublicKey::class.java).newInstance(), - sandboxKey - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showPublicKey = classLoader.createTaskFor(taskFactory, ShowPublicKey::class.java) + val result = showPublicKey.apply(sandboxKey) ?: fail("Result cannot be null") assertEquals(ShowPublicKey().apply(publicKey), result.toString()) assertEquals(SANDBOX_STRING, result::class.java.name) @@ -73,11 +71,9 @@ class DeserializePublicKeyTest : TestBase(KOTLIN) { val sandboxKey = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowPublicKey::class.java).newInstance(), - sandboxKey - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showPublicKey = classLoader.createTaskFor(taskFactory, ShowPublicKey::class.java) + val result = showPublicKey.apply(sandboxKey) ?: fail("Result cannot be null") assertEquals(ShowPublicKey().apply(compositeData), result.toString()) } diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeStringBufferTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeStringBufferTest.kt index 6ae12c8c66..9de18f8a3f 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeStringBufferTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeStringBufferTest.kt @@ -19,13 +19,11 @@ class DeserializeStringBufferTest : TestBase(KOTLIN) { sandbox { _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) - val sandboxBigInteger = data.deserializeFor(classLoader) + val sandboxBuffer = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowStringBuffer::class.java).newInstance(), - sandboxBigInteger - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showStringBuffer = classLoader.createTaskFor(taskFactory, ShowStringBuffer::class.java) + val result = showStringBuffer.apply(sandboxBuffer) ?: fail("Result cannot be null") assertEquals(ShowStringBuffer().apply(buffer), result.toString()) assertEquals(SANDBOX_STRING, result::class.java.name) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeStringTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeStringTest.kt index 860952a8ab..f0004b5d21 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeStringTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeStringTest.kt @@ -22,11 +22,9 @@ class DeserializeStringTest : TestBase(KOTLIN) { val sandboxString = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowStringMessage::class.java).newInstance(), - sandboxString - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showStringMessage = classLoader.createTaskFor(taskFactory, ShowStringMessage::class.java) + val result = showStringMessage.apply(sandboxString) ?: fail("Result cannot be null") assertEquals(stringMessage.message, result.toString()) assertEquals(SANDBOX_STRING, result::class.java.name) @@ -51,11 +49,9 @@ class DeserializeStringTest : TestBase(KOTLIN) { val sandboxListArray = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowStringListOfArray::class.java).newInstance(), - sandboxListArray - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showStringListOfArray = classLoader.createTaskFor(taskFactory, ShowStringListOfArray::class.java) + val result = showStringListOfArray.apply(sandboxListArray) ?: fail("Result cannot be null") assertEquals(stringListArray.data.flatMap(Array::toList).joinToString(), result.toString()) } diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeYearMonthTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeYearMonthTest.kt index 0369972dc6..1589cd4f5f 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeYearMonthTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeYearMonthTest.kt @@ -22,11 +22,9 @@ class DeserializeYearMonthTest : TestBase(KOTLIN) { val sandboxYearMonth = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowYearMonth::class.java).newInstance(), - sandboxYearMonth - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showYearMonth = classLoader.createTaskFor(taskFactory, ShowYearMonth::class.java) + val result = showYearMonth.apply(sandboxYearMonth) ?: fail("Result cannot be null") assertEquals(yearMonth.toString(), result.toString()) assertEquals(SANDBOX_STRING, result::class.java.name) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeYearTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeYearTest.kt index 5056586636..450ea05723 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeYearTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeYearTest.kt @@ -22,11 +22,9 @@ class DeserializeYearTest : TestBase(KOTLIN) { val sandboxYear = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowYear::class.java).newInstance(), - sandboxYear - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showYear = classLoader.createTaskFor(taskFactory, ShowYear::class.java) + val result = showYear.apply(sandboxYear) ?: fail("Result cannot be null") assertEquals(year.toString(), result.toString()) assertEquals(SANDBOX_STRING, result::class.java.name) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeZoneIdTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeZoneIdTest.kt index 27afdf6978..278dd6f629 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeZoneIdTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeZoneIdTest.kt @@ -34,11 +34,9 @@ class DeserializeZoneIdTest : TestBase(KOTLIN) { val sandboxZoneId = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowZoneId::class.java).newInstance(), - sandboxZoneId - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showZoneId = classLoader.createTaskFor(taskFactory, ShowZoneId::class.java) + val result = showZoneId.apply(sandboxZoneId) ?: fail("Result cannot be null") assertEquals(zoneId.toString(), result.toString()) assertEquals(SANDBOX_STRING, result::class.java.name) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeZonedDateTimeTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeZonedDateTimeTest.kt index 70a8f6b03b..df30c9208b 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeZonedDateTimeTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeZonedDateTimeTest.kt @@ -22,11 +22,9 @@ class DeserializeZonedDateTimeTest : TestBase(KOTLIN) { val sandboxDateTime = data.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowZonedDateTime::class.java).newInstance(), - sandboxDateTime - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showZonedDateTime = classLoader.createTaskFor(taskFactory, ShowZonedDateTime::class.java) + val result = showZonedDateTime.apply(sandboxDateTime) ?: fail("Result cannot be null") assertEquals(dateTime.toString(), result.toString()) assertEquals(SANDBOX_STRING, result::class.java.name) diff --git a/src/test/kotlin/net/corda/djvm/serialization/SafeDeserialisationTest.kt b/src/test/kotlin/net/corda/djvm/serialization/SafeDeserialisationTest.kt index cf7d9cd8be..6aa5d5b520 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/SafeDeserialisationTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/SafeDeserialisationTest.kt @@ -45,11 +45,9 @@ class SafeDeserialisationTest : TestBase(KOTLIN) { val sandboxData = evilData.deserializeFor(classLoader) - val executor = createExecutorFor(classLoader) - val result = executor.apply( - classLoader.loadClassForSandbox(ShowInnocentData::class.java).newInstance(), - sandboxData - ) ?: fail("Result cannot be null") + val taskFactory = classLoader.createRawTaskFactory() + val showInnocentData = classLoader.createTaskFor(taskFactory, ShowInnocentData::class.java) + val result = showInnocentData.apply(sandboxData) ?: fail("Result cannot be null") // Check that we have deserialised the data without instantiating the Evil class. assertThat(result.toString()) diff --git a/src/test/kotlin/net/corda/djvm/serialization/TestBase.kt b/src/test/kotlin/net/corda/djvm/serialization/TestBase.kt index 29af995f0f..6c698dfb3d 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/TestBase.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/TestBase.kt @@ -11,7 +11,6 @@ import net.corda.djvm.SandboxRuntimeContext import net.corda.djvm.analysis.AnalysisConfiguration import net.corda.djvm.analysis.Whitelist.Companion.MINIMAL import net.corda.djvm.execution.ExecutionProfile.* -import net.corda.djvm.execution.SandboxRuntimeException import net.corda.djvm.messages.Severity import net.corda.djvm.messages.Severity.* import net.corda.djvm.rewiring.SandboxClassLoader @@ -21,12 +20,10 @@ import org.junit.jupiter.api.AfterAll import org.junit.jupiter.api.BeforeAll import org.junit.jupiter.api.fail import java.io.File -import java.lang.reflect.InvocationTargetException import java.nio.file.Files.exists import java.nio.file.Files.isDirectory import java.nio.file.Path import java.nio.file.Paths -import java.util.function.BiFunction import kotlin.concurrent.thread @Suppress("unused", "MemberVisibilityCanBePrivate") @@ -121,21 +118,4 @@ abstract class TestBase(type: SandboxType) { }.join() throw thrownException ?: return } - - fun createExecutorFor(classLoader: SandboxClassLoader): BiFunction { - val taskClass = classLoader.loadClass("sandbox.RawTask") - val taskApply = taskClass.getDeclaredMethod("apply", Any::class.java) - val taskConstructor = taskClass.getDeclaredConstructor(classLoader.loadClass("sandbox.java.util.function.Function")) - return BiFunction { userTask, arg -> - try { - taskApply(taskConstructor.newInstance(userTask), arg) - } catch (ex: InvocationTargetException) { - val target = ex.targetException - throw when (target) { - is RuntimeException, is Error -> target - else -> SandboxRuntimeException(target.message, target) - } - } - } - } -} \ No newline at end of file +} From 1a53f1a22a9ff128991d19135b9368ad5c1ef66c Mon Sep 17 00:00:00 2001 From: Chris Rankin Date: Tue, 10 Sep 2019 11:50:02 +0100 Subject: [PATCH 05/18] CORDA-2871: Ensure ClassLoader.loadClass() throws ClassNotFoundException for all cases where the class cannot be found. (#64) --- .../DeserializeKotlinAliasTest.kt | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 src/test/kotlin/net/corda/djvm/serialization/DeserializeKotlinAliasTest.kt diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeKotlinAliasTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeKotlinAliasTest.kt new file mode 100644 index 0000000000..aecdd740d3 --- /dev/null +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeKotlinAliasTest.kt @@ -0,0 +1,69 @@ +package net.corda.djvm.serialization + +import net.corda.core.crypto.SecureHash +import net.corda.core.node.services.AttachmentId +import net.corda.core.serialization.CordaSerializable +import net.corda.core.serialization.internal._contextSerializationEnv +import net.corda.core.serialization.serialize +import net.corda.djvm.serialization.SandboxType.* +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.junit.jupiter.api.fail +import java.util.function.Function + +@ExtendWith(LocalSerialization::class) +class DeserializeKotlinAliasTest : TestBase(KOTLIN) { + @Test + fun `test deserializing kotlin alias`() { + val attachmentId = SecureHash.allOnesHash + val data = attachmentId.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxAttachmentId = data.deserializeFor(classLoader) + + val taskFactory = classLoader.createRawTaskFactory() + val showAlias = classLoader.createTaskFor(taskFactory, ShowAlias::class.java) + val result = showAlias.apply(sandboxAttachmentId) ?: fail("Result cannot be null") + + assertEquals(ShowAlias().apply(attachmentId), result.toString()) + assertEquals(SANDBOX_STRING, result::class.java.name) + } + } + + class ShowAlias : Function { + override fun apply(id: AttachmentId): String { + return id.toString() + } + } + + @Test + fun `test deserializing data with kotlin alias`() { + val attachment = AttachmentData(SecureHash.allOnesHash) + val data = attachment.serialize() + + sandbox { + _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) + + val sandboxAttachment = data.deserializeFor(classLoader) + + val taskFactory = classLoader.createRawTaskFactory() + val showAliasData = classLoader.createTaskFor(taskFactory, ShowAliasData::class.java) + val result = showAliasData.apply(sandboxAttachment) ?: fail("Result cannot be null") + + assertEquals(ShowAliasData().apply(attachment), result.toString()) + assertEquals(SANDBOX_STRING, result::class.java.name) + } + } + + class ShowAliasData: Function { + override fun apply(data: AttachmentData): String { + return data.toString() + } + } +} + +@CordaSerializable +data class AttachmentData(val id: AttachmentId) From e0ce1bd5250a1bf58b2ac9393c6e5a417482a68e Mon Sep 17 00:00:00 2001 From: Chris Rankin Date: Thu, 12 Sep 2019 15:11:08 +0100 Subject: [PATCH 06/18] CORDA-2871: Refactor SourceClassLoader to define source classes. (#66) * Rewrite SourceClassLoader to support parent/child relationships. * Revert catching TypNotPresebtException - it was a symptom of a bigger problem. * Remove AutoCloseable from AnalysisConfiguration and SourceClassLoader. * SourceClassLoader.getResource() must delegate to its parent first. --- build.gradle | 2 +- .../SandboxSerializerFactoryFactory.kt | 7 ++++++- .../corda/djvm/serialization/Serialization.kt | 5 ++--- .../net/corda/djvm/serialization/TestBase.kt | 17 ++++++++++------- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/build.gradle b/build.gradle index 6fbcc81d9c..a10d7ba6c1 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { } ext { - corda_version = '5.0-SNAPSHOT' + corda_version = '4.3-SNAPSHOT' } description 'Serialization support for the DJVM' diff --git a/src/main/kotlin/net/corda/djvm/serialization/SandboxSerializerFactoryFactory.kt b/src/main/kotlin/net/corda/djvm/serialization/SandboxSerializerFactoryFactory.kt index 442a3265ca..d6afa000fd 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/SandboxSerializerFactoryFactory.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/SandboxSerializerFactoryFactory.kt @@ -10,6 +10,7 @@ import java.lang.Double import java.lang.Float import java.lang.Long import java.lang.Short +import java.util.* import java.util.Collections.singleton import java.util.Collections.unmodifiableMap import java.util.function.Function @@ -32,7 +33,11 @@ class SandboxSerializerFactoryFactory( classLoader.loadClass("sandbox.java.lang.Float") to Float.TYPE, classLoader.loadClass("sandbox.java.lang.Integer") to Integer.TYPE, classLoader.loadClass("sandbox.java.lang.Long") to Long.TYPE, - classLoader.loadClass("sandbox.java.lang.Short") to Short.TYPE + classLoader.loadClass("sandbox.java.lang.Short") to Short.TYPE, + classLoader.loadClass("sandbox.java.lang.String") to String::class.java, + classLoader.loadClass("sandbox.java.util.Date") to Date::class.java, + classLoader.loadClass("sandbox.java.util.UUID") to UUID::class.java, + Void::class.java to Void.TYPE )) val classCarpenter = createClassCarpenter(context) diff --git a/src/main/kotlin/net/corda/djvm/serialization/Serialization.kt b/src/main/kotlin/net/corda/djvm/serialization/Serialization.kt index f286fcf2a8..52b02a61eb 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/Serialization.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/Serialization.kt @@ -54,11 +54,10 @@ fun createSandboxSerializationEnv(classLoader: SandboxClassLoader): Serializatio inline fun SerializedBytes.deserializeFor(classLoader: SandboxClassLoader): Any { val clazz = classLoader.toSandboxClass(T::class.java) - return deserializeTo(clazz, classLoader) + return deserializeTo(clazz, classLoader, SerializationFactory.defaultFactory) } -fun ByteSequence.deserializeTo(clazz: Class<*>, classLoader: SandboxClassLoader): Any { - val factory = SerializationFactory.defaultFactory +fun ByteSequence.deserializeTo(clazz: Class<*>, classLoader: SandboxClassLoader, factory: SerializationFactory): Any { return deserializeTo(clazz, classLoader, factory, factory.defaultContext) } diff --git a/src/test/kotlin/net/corda/djvm/serialization/TestBase.kt b/src/test/kotlin/net/corda/djvm/serialization/TestBase.kt index 6c698dfb3d..ade9a41fa0 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/TestBase.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/TestBase.kt @@ -39,12 +39,14 @@ abstract class TestBase(type: SandboxType) { val TESTING_LIBRARIES: List = (System.getProperty("sandbox-libraries.path") ?: fail("sandbox-libraries.path property not set")) .split(File.pathSeparator).map { Paths.get(it) }.filter { exists(it) } + private lateinit var bootstrapClassLoader: BootstrapClassLoader private lateinit var configuration: SandboxConfiguration private lateinit var classLoader: SandboxClassLoader @BeforeAll @JvmStatic fun setupClassLoader() { + bootstrapClassLoader = BootstrapClassLoader(DETERMINISTIC_RT) val rootConfiguration = AnalysisConfiguration.createRoot( userSource = UserPathSource(emptyList()), whitelist = MINIMAL, @@ -53,7 +55,7 @@ abstract class TestBase(type: SandboxType) { ConstructorForDeserialization::class.java, DeprecatedConstructorForDeserialization::class.java ), - bootstrapSource = BootstrapClassLoader(DETERMINISTIC_RT) + bootstrapSource = bootstrapClassLoader ) configuration = SandboxConfiguration.of( UNLIMITED, @@ -69,7 +71,7 @@ abstract class TestBase(type: SandboxType) { @AfterAll @JvmStatic fun destroyRootContext() { - configuration.analysisConfiguration.closeAll() + bootstrapClassLoader.close() } } @@ -95,11 +97,12 @@ abstract class TestBase(type: SandboxType) { var thrownException: Throwable? = null thread { try { - configuration.analysisConfiguration.createChild( - userSource = UserPathSource(classPaths), - newMinimumSeverityLevel = minimumSeverityLevel, - visibleAnnotations = visibleAnnotations - ).use { analysisConfiguration -> + UserPathSource(classPaths).use { userSource -> + val analysisConfiguration = configuration.analysisConfiguration.createChild( + userSource = userSource, + newMinimumSeverityLevel = minimumSeverityLevel, + visibleAnnotations = visibleAnnotations + ) SandboxRuntimeContext(SandboxConfiguration.of( configuration.executionProfile, configuration.rules, From 394d503d41fbeca0f8cae316ff60d16191e25078 Mon Sep 17 00:00:00 2001 From: Chris Rankin Date: Sat, 14 Sep 2019 14:00:23 +0100 Subject: [PATCH 07/18] CORDA-3218: Align DJVM with internal Corda Serialisation API. (#68) * Align DJVM with internal Corda Serialisation API. * Ensure we get the latest SNAPSHOT of the serialisation code. --- build.gradle | 7 ++++++- .../djvm/serialization/SandboxSerializerFactoryFactory.kt | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index a10d7ba6c1..bf5254cc47 100644 --- a/build.gradle +++ b/build.gradle @@ -25,7 +25,7 @@ allprojects { } } - configurations{ + configurations { // This is for the latest deterministic Corda SNAPSHOT artifacts... [ compileClasspath, runtimeClasspath ].forEach { cfg -> cfg.resolutionStrategy { @@ -38,6 +38,11 @@ allprojects { } } } + + testRuntimeClasspath.resolutionStrategy { + // Always check the repository for a newer SNAPSHOT. + cacheChangingModulesFor 0, 'seconds' + } } /* diff --git a/src/main/kotlin/net/corda/djvm/serialization/SandboxSerializerFactoryFactory.kt b/src/main/kotlin/net/corda/djvm/serialization/SandboxSerializerFactoryFactory.kt index d6afa000fd..9b15bcfe6b 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/SandboxSerializerFactoryFactory.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/SandboxSerializerFactoryFactory.kt @@ -14,6 +14,7 @@ import java.util.* import java.util.Collections.singleton import java.util.Collections.unmodifiableMap import java.util.function.Function +import java.util.function.Predicate /** * This has all been lovingly copied from [SerializerFactoryBuilder]. @@ -60,6 +61,7 @@ class SandboxSerializerFactoryFactory( classloader = classLoader, descriptorBasedSerializerRegistry = descriptorBasedSerializerRegistry, primitiveSerializerFactory = primitiveSerializerFactory, + isPrimitiveType = Predicate { clazz -> clazz.isPrimitive || clazz in primitiveTypes.keys }, customSerializerRegistry = customSerializerRegistry, onlyCustomSerializers = false ) From 8718433be6862b3927f983180c3988a7f2b8c4d1 Mon Sep 17 00:00:00 2001 From: Chris Rankin Date: Sun, 15 Sep 2019 01:28:31 +0100 Subject: [PATCH 08/18] CORDA-2871: Minor cosmetic fixes. (#69) --- .../corda/djvm/serialization/deserializers/DescribeEnum.kt | 4 ++-- .../net/corda/djvm/serialization/DeserializeEnumTest.kt | 2 +- src/test/kotlin/net/corda/djvm/serialization/TestBase.kt | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/DescribeEnum.kt b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/DescribeEnum.kt index 1d8d7e371e..6db4c223af 100644 --- a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/DescribeEnum.kt +++ b/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/DescribeEnum.kt @@ -2,8 +2,8 @@ package net.corda.djvm.serialization.deserializers import java.util.function.Function -class DescribeEnum : Function, Array> { - override fun apply(enumClass: Class<*>): Array { +class DescribeEnum : Function, Array> { + override fun apply(enumClass: Class<*>): Array { return enumClass.enumConstants } } diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeEnumTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeEnumTest.kt index 4d4784a5c2..417d76446e 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeEnumTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeEnumTest.kt @@ -17,7 +17,7 @@ class DeserializeEnumTest : TestBase(KOTLIN) { @EnumSource(ExampleEnum::class) fun `test deserialize basic enum`(value: ExampleEnum) { val example = ExampleData(value) - val data =example.serialize() + val data = example.serialize() sandbox { _contextSerializationEnv.set(createSandboxSerializationEnv(classLoader)) diff --git a/src/test/kotlin/net/corda/djvm/serialization/TestBase.kt b/src/test/kotlin/net/corda/djvm/serialization/TestBase.kt index ade9a41fa0..8495c8a209 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/TestBase.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/TestBase.kt @@ -41,7 +41,7 @@ abstract class TestBase(type: SandboxType) { private lateinit var bootstrapClassLoader: BootstrapClassLoader private lateinit var configuration: SandboxConfiguration - private lateinit var classLoader: SandboxClassLoader + private lateinit var parentClassLoader: SandboxClassLoader @BeforeAll @JvmStatic @@ -65,7 +65,7 @@ abstract class TestBase(type: SandboxType) { true, rootConfiguration ) - classLoader = SandboxClassLoader.createFor(configuration) + parentClassLoader = SandboxClassLoader.createFor(configuration) } @AfterAll @@ -110,7 +110,7 @@ abstract class TestBase(type: SandboxType) { configuration.definitionProviders, enableTracing, analysisConfiguration, - classLoader + parentClassLoader )).use { action(this) } From d60430856388826d54317964b3d2da897e18590c Mon Sep 17 00:00:00 2001 From: Chris Rankin Date: Thu, 19 Sep 2019 22:04:24 +0100 Subject: [PATCH 09/18] CORDA-3137: Enhance annotation handling so that we can allow some annotations to be mapped into the sandbox without also needing to be stitched. (#72) --- build.gradle | 3 +++ .../kotlin/net/corda/djvm/serialization/TestBase.kt | 12 +++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index bf5254cc47..9ba3dc5beb 100644 --- a/build.gradle +++ b/build.gradle @@ -23,6 +23,9 @@ allprojects { maven { url "$artifactory_contextUrl/corda-dev" } + maven { + url "$artifactory_contextUrl/corda-dependencies" + } } configurations { diff --git a/src/test/kotlin/net/corda/djvm/serialization/TestBase.kt b/src/test/kotlin/net/corda/djvm/serialization/TestBase.kt index 8495c8a209..1a5a90e7a0 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/TestBase.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/TestBase.kt @@ -81,16 +81,21 @@ abstract class TestBase(type: SandboxType) { } fun sandbox(action: SandboxRuntimeContext.() -> Unit) { - return sandbox(WARNING, emptySet(), false, action) + return sandbox(WARNING, emptySet(), emptySet(), false, action) } fun sandbox(visibleAnnotations: Set>, action: SandboxRuntimeContext.() -> Unit) { - return sandbox(WARNING, visibleAnnotations, false, action) + return sandbox(WARNING, visibleAnnotations, emptySet(), false, action) + } + + fun sandbox(visibleAnnotations: Set>, sandboxOnlyAnnotations: Set, action: SandboxRuntimeContext.() -> Unit) { + return sandbox(WARNING, visibleAnnotations, sandboxOnlyAnnotations, false, action) } fun sandbox( minimumSeverityLevel: Severity, visibleAnnotations: Set>, + sandboxOnlyAnnotations: Set, enableTracing: Boolean, action: SandboxRuntimeContext.() -> Unit ) { @@ -101,7 +106,8 @@ abstract class TestBase(type: SandboxType) { val analysisConfiguration = configuration.analysisConfiguration.createChild( userSource = userSource, newMinimumSeverityLevel = minimumSeverityLevel, - visibleAnnotations = visibleAnnotations + visibleAnnotations = visibleAnnotations, + sandboxOnlyAnnotations = sandboxOnlyAnnotations ) SandboxRuntimeContext(SandboxConfiguration.of( configuration.executionProfile, From ed23c4b9983532889541b6c9b212e91689aec780 Mon Sep 17 00:00:00 2001 From: Chris Rankin Date: Thu, 26 Sep 2019 17:50:40 +0100 Subject: [PATCH 10/18] CORDA-2877: Load bytecode from a persistent cache to prevent repeated rewriting. (#75) * Load bytecode from a persistent cache to prevent repeated rewriting. * Refactor byte-code cache to SandboxConfiguration instead of AnalysisConfiguration. We cannot "mix and match" byte-code generated by different sets of rules. --- .../net/corda/djvm/serialization/TestBase.kt | 37 +++++-------------- 1 file changed, 9 insertions(+), 28 deletions(-) diff --git a/src/test/kotlin/net/corda/djvm/serialization/TestBase.kt b/src/test/kotlin/net/corda/djvm/serialization/TestBase.kt index 1a5a90e7a0..706f11a4f4 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/TestBase.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/TestBase.kt @@ -4,16 +4,12 @@ import net.corda.core.serialization.ConstructorForDeserialization import net.corda.core.serialization.CordaSerializable import net.corda.core.serialization.DeprecatedConstructorForDeserialization import net.corda.djvm.SandboxConfiguration -import net.corda.djvm.SandboxConfiguration.Companion.ALL_DEFINITION_PROVIDERS -import net.corda.djvm.SandboxConfiguration.Companion.ALL_EMITTERS -import net.corda.djvm.SandboxConfiguration.Companion.ALL_RULES import net.corda.djvm.SandboxRuntimeContext import net.corda.djvm.analysis.AnalysisConfiguration import net.corda.djvm.analysis.Whitelist.Companion.MINIMAL import net.corda.djvm.execution.ExecutionProfile.* import net.corda.djvm.messages.Severity import net.corda.djvm.messages.Severity.* -import net.corda.djvm.rewiring.SandboxClassLoader import net.corda.djvm.source.BootstrapClassLoader import net.corda.djvm.source.UserPathSource import org.junit.jupiter.api.AfterAll @@ -40,8 +36,7 @@ abstract class TestBase(type: SandboxType) { .split(File.pathSeparator).map { Paths.get(it) }.filter { exists(it) } private lateinit var bootstrapClassLoader: BootstrapClassLoader - private lateinit var configuration: SandboxConfiguration - private lateinit var parentClassLoader: SandboxClassLoader + private lateinit var parentConfiguration: SandboxConfiguration @BeforeAll @JvmStatic @@ -57,15 +52,11 @@ abstract class TestBase(type: SandboxType) { ), bootstrapSource = bootstrapClassLoader ) - configuration = SandboxConfiguration.of( - UNLIMITED, - ALL_RULES, - ALL_EMITTERS, - ALL_DEFINITION_PROVIDERS, - true, - rootConfiguration + parentConfiguration = SandboxConfiguration.createFor( + analysisConfiguration = rootConfiguration, + profile = UNLIMITED, + enableTracing = false ) - parentClassLoader = SandboxClassLoader.createFor(configuration) } @AfterAll @@ -81,42 +72,32 @@ abstract class TestBase(type: SandboxType) { } fun sandbox(action: SandboxRuntimeContext.() -> Unit) { - return sandbox(WARNING, emptySet(), emptySet(), false, action) + return sandbox(WARNING, emptySet(), emptySet(), action) } fun sandbox(visibleAnnotations: Set>, action: SandboxRuntimeContext.() -> Unit) { - return sandbox(WARNING, visibleAnnotations, emptySet(), false, action) + return sandbox(WARNING, visibleAnnotations, emptySet(), action) } fun sandbox(visibleAnnotations: Set>, sandboxOnlyAnnotations: Set, action: SandboxRuntimeContext.() -> Unit) { - return sandbox(WARNING, visibleAnnotations, sandboxOnlyAnnotations, false, action) + return sandbox(WARNING, visibleAnnotations, sandboxOnlyAnnotations, action) } fun sandbox( minimumSeverityLevel: Severity, visibleAnnotations: Set>, sandboxOnlyAnnotations: Set, - enableTracing: Boolean, action: SandboxRuntimeContext.() -> Unit ) { var thrownException: Throwable? = null thread { try { UserPathSource(classPaths).use { userSource -> - val analysisConfiguration = configuration.analysisConfiguration.createChild( + SandboxRuntimeContext(parentConfiguration.createChild( userSource = userSource, newMinimumSeverityLevel = minimumSeverityLevel, visibleAnnotations = visibleAnnotations, sandboxOnlyAnnotations = sandboxOnlyAnnotations - ) - SandboxRuntimeContext(SandboxConfiguration.of( - configuration.executionProfile, - configuration.rules, - configuration.emitters, - configuration.definitionProviders, - enableTracing, - analysisConfiguration, - parentClassLoader )).use { action(this) } From 3d0a4aa61420e41fc3948472590bc052e54c139e Mon Sep 17 00:00:00 2001 From: Chris Rankin Date: Mon, 30 Sep 2019 10:07:02 +0100 Subject: [PATCH 11/18] CORDA-2877: Refactor how we create child SandboxConfiguration objects. (#76) --- .../kotlin/net/corda/djvm/serialization/TestBase.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/test/kotlin/net/corda/djvm/serialization/TestBase.kt b/src/test/kotlin/net/corda/djvm/serialization/TestBase.kt index 706f11a4f4..0e9bbd365d 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/TestBase.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/TestBase.kt @@ -20,6 +20,7 @@ import java.nio.file.Files.exists import java.nio.file.Files.isDirectory import java.nio.file.Path import java.nio.file.Paths +import java.util.function.Consumer import kotlin.concurrent.thread @Suppress("unused", "MemberVisibilityCanBePrivate") @@ -93,12 +94,11 @@ abstract class TestBase(type: SandboxType) { thread { try { UserPathSource(classPaths).use { userSource -> - SandboxRuntimeContext(parentConfiguration.createChild( - userSource = userSource, - newMinimumSeverityLevel = minimumSeverityLevel, - visibleAnnotations = visibleAnnotations, - sandboxOnlyAnnotations = sandboxOnlyAnnotations - )).use { + SandboxRuntimeContext(parentConfiguration.createChild(userSource, Consumer { + it.withNewMinimumSeverityLevel(minimumSeverityLevel) + .withSandboxOnlyAnnotations(sandboxOnlyAnnotations) + .withVisibleAnnotations(visibleAnnotations) + })).use { action(this) } } From a910ac9b6763dc07c8f8bee895c82ec44e6b2465 Mon Sep 17 00:00:00 2001 From: Chris Rankin Date: Thu, 3 Oct 2019 09:10:05 +0100 Subject: [PATCH 12/18] CORDA-3292: Reimplement ExecutionProfile as a data class. (#80) --- src/test/kotlin/net/corda/djvm/serialization/TestBase.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/kotlin/net/corda/djvm/serialization/TestBase.kt b/src/test/kotlin/net/corda/djvm/serialization/TestBase.kt index 0e9bbd365d..1ba0fd41d5 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/TestBase.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/TestBase.kt @@ -7,7 +7,7 @@ import net.corda.djvm.SandboxConfiguration import net.corda.djvm.SandboxRuntimeContext import net.corda.djvm.analysis.AnalysisConfiguration import net.corda.djvm.analysis.Whitelist.Companion.MINIMAL -import net.corda.djvm.execution.ExecutionProfile.* +import net.corda.djvm.execution.ExecutionProfile.Companion.UNLIMITED import net.corda.djvm.messages.Severity import net.corda.djvm.messages.Severity.* import net.corda.djvm.source.BootstrapClassLoader From ecc5ace4c7e381b30a0ec8e2501aed494f903289 Mon Sep 17 00:00:00 2001 From: Chris Rankin Date: Thu, 3 Oct 2019 16:56:23 +0100 Subject: [PATCH 13/18] Fix tests broken by Windows line endings. (#82) --- .../serialization/DeserializeCertificatesTest.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeCertificatesTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeCertificatesTest.kt index 95e6d48b47..9b9b668ce1 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeCertificatesTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeCertificatesTest.kt @@ -26,9 +26,9 @@ import java.util.function.Function class DeserializeCertificatesTest : TestBase(KOTLIN) { companion object { // The sandbox's localisation may not match that of the host. - // E.g. line separator characters and time zone format. - fun localise(str: String): String { - return str.replace("\n", System.lineSeparator()) + // E.g. line separator characters. + fun String.toUNIX(): String { + return replace(System.lineSeparator(), "\n") } val factory: CertificateFactory = CertificateFactory.getInstance("X.509") @@ -58,7 +58,7 @@ class DeserializeCertificatesTest : TestBase(KOTLIN) { val showCertPath = classLoader.createTaskFor(taskFactory, ShowCertPath::class.java) val result = showCertPath.apply(sandboxCertPath) ?: fail("Result cannot be null") - assertEquals(ShowCertPath().apply(certPath), localise(result.toString())) + assertEquals(ShowCertPath().apply(certPath).toUNIX(), result.toString()) assertThat(result::class.java.name).startsWith("sandbox.") } } @@ -82,7 +82,7 @@ class DeserializeCertificatesTest : TestBase(KOTLIN) { val showCertificate = classLoader.createTaskFor(taskFactory, ShowCertificate::class.java) val result = showCertificate.apply(sandboxCertificate) ?: fail("Result cannot be null") - assertEquals(ShowCertificate().apply(certificate), localise(result.toString())) + assertEquals(ShowCertificate().apply(certificate).toUNIX(), result.toString()) assertThat(result::class.java.name).startsWith("sandbox.") } } @@ -116,7 +116,7 @@ class DeserializeCertificatesTest : TestBase(KOTLIN) { val showCRL = classLoader.createTaskFor(taskFactory, ShowCRL::class.java) val result = showCRL.apply(sandboxCRL) ?: fail("Result cannot be null") - assertEquals(ShowCRL().apply(crl), localise(result.toString())) + assertEquals(ShowCRL().apply(crl).toUNIX(), result.toString()) assertThat(result::class.java.name).startsWith("sandbox.") } } From 90c2f7f129615202aadadc850b70d57886f9ba65 Mon Sep 17 00:00:00 2001 From: Chris Rankin Date: Tue, 8 Oct 2019 14:57:46 +0100 Subject: [PATCH 14/18] CORDA-3309: Install UncaughtExceptionHandler for DJVM tasks. (#88) --- .../kotlin/net/corda/djvm/serialization/TestBase.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/test/kotlin/net/corda/djvm/serialization/TestBase.kt b/src/test/kotlin/net/corda/djvm/serialization/TestBase.kt index 1ba0fd41d5..167b2cc1dd 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/TestBase.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/TestBase.kt @@ -91,7 +91,7 @@ abstract class TestBase(type: SandboxType) { action: SandboxRuntimeContext.() -> Unit ) { var thrownException: Throwable? = null - thread { + thread(start = false) { try { UserPathSource(classPaths).use { userSource -> SandboxRuntimeContext(parentConfiguration.createChild(userSource, Consumer { @@ -105,7 +105,13 @@ abstract class TestBase(type: SandboxType) { } catch (exception: Throwable) { thrownException = exception } - }.join() + }.apply { + uncaughtExceptionHandler = Thread.UncaughtExceptionHandler { _, ex -> + thrownException = ex + } + start() + join() + } throw thrownException ?: return } } From 83ad11f21b563013a4b1a0bdffb355162e48f366 Mon Sep 17 00:00:00 2001 From: Chris Rankin Date: Wed, 9 Oct 2019 09:45:44 +0100 Subject: [PATCH 15/18] CORDA-3309: Remove explicit try-catch in favour of UncaughtExceptionHandler. (#91) --- .../net/corda/djvm/serialization/TestBase.kt | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/test/kotlin/net/corda/djvm/serialization/TestBase.kt b/src/test/kotlin/net/corda/djvm/serialization/TestBase.kt index 167b2cc1dd..e8115c482d 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/TestBase.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/TestBase.kt @@ -92,18 +92,14 @@ abstract class TestBase(type: SandboxType) { ) { var thrownException: Throwable? = null thread(start = false) { - try { - UserPathSource(classPaths).use { userSource -> - SandboxRuntimeContext(parentConfiguration.createChild(userSource, Consumer { - it.withNewMinimumSeverityLevel(minimumSeverityLevel) - .withSandboxOnlyAnnotations(sandboxOnlyAnnotations) - .withVisibleAnnotations(visibleAnnotations) - })).use { - action(this) - } + UserPathSource(classPaths).use { userSource -> + SandboxRuntimeContext(parentConfiguration.createChild(userSource, Consumer { + it.withNewMinimumSeverityLevel(minimumSeverityLevel) + .withSandboxOnlyAnnotations(sandboxOnlyAnnotations) + .withVisibleAnnotations(visibleAnnotations) + })).use { + action(this) } - } catch (exception: Throwable) { - thrownException = exception } }.apply { uncaughtExceptionHandler = Thread.UncaughtExceptionHandler { _, ex -> From c0e62d0dfd4a907b9c76eb0231a5735417895b5c Mon Sep 17 00:00:00 2001 From: Chris Rankin Date: Mon, 21 Oct 2019 14:11:51 +0100 Subject: [PATCH 16/18] CORDA-3330: Allow DJVM to preload / pregenerate classes from selected jars. (#92) * Add support for SourceClassLoader.getResources(). * Allow a SandboxConfiguration to preload sandbox byte-code for all classes inside jars containing META-INF/DJVM-preload. --- deserializers/src/main/resources/META-INF/DJVM-preload | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 deserializers/src/main/resources/META-INF/DJVM-preload diff --git a/deserializers/src/main/resources/META-INF/DJVM-preload b/deserializers/src/main/resources/META-INF/DJVM-preload new file mode 100644 index 0000000000..e69de29bb2 From bdd33772238c9bfa47a18ec5333cf2382b34d514 Mon Sep 17 00:00:00 2001 From: Chris Rankin Date: Tue, 22 Oct 2019 09:23:16 +0100 Subject: [PATCH 17/18] Update to use Corda 4.4-SNAPSHOT. (#95) --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 9ba3dc5beb..d31153ab1c 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { } ext { - corda_version = '4.3-SNAPSHOT' + corda_version = '4.4-SNAPSHOT' } description 'Serialization support for the DJVM' From 2157df03b81292a989486d3dcdf7042bc2646757 Mon Sep 17 00:00:00 2001 From: Chris Rankin Date: Tue, 22 Oct 2019 14:30:02 +0100 Subject: [PATCH 18/18] Migrate DJVM serialization modules into Corda. --- build.gradle => serialization-djvm/build.gradle | 0 .../deserializers}/build.gradle | 0 .../deserializers/BitSetDeserializer.kt | 0 .../deserializers/CertPathDeserializer.kt | 0 .../deserializers/ClassDeserializer.kt | 0 .../serialization/deserializers/CreateCollection.kt | 0 .../serialization/deserializers/CreateCurrency.kt | 0 .../serialization/deserializers/CreateFromString.kt | 0 .../djvm/serialization/deserializers/CreateMap.kt | 0 .../deserializers/Decimal128Deserializer.kt | 0 .../deserializers/Decimal32Deserializer.kt | 0 .../deserializers/Decimal64Deserializer.kt | 0 .../serialization/deserializers/DescribeEnum.kt | 0 .../deserializers/DurationDeserializer.kt | 0 .../deserializers/EnumSetDeserializer.kt | 0 .../deserializers/InputStreamDeserializer.kt | 0 .../deserializers/InstantDeserializer.kt | 0 .../serialization/deserializers/JustForCasting.kt | 0 .../deserializers/LocalDateDeserializer.kt | 0 .../deserializers/LocalDateTimeDeserializer.kt | 0 .../deserializers/LocalTimeDeserializer.kt | 0 .../deserializers/MonthDayDeserializer.kt | 0 .../deserializers/OffsetDateTimeDeserializer.kt | 0 .../deserializers/OffsetTimeDeserializer.kt | 0 .../OpaqueBytesSubSequenceDeserializer.kt | 0 .../deserializers/OptionalDeserializer.kt | 0 .../deserializers/PeriodDeserializer.kt | 0 .../serialization/deserializers/PublicKeyDecoder.kt | 0 .../deserializers/SymbolDeserializer.kt | 0 .../deserializers/UnsignedByteDeserializer.kt | 0 .../deserializers/UnsignedIntegerDeserializer.kt | 0 .../deserializers/UnsignedLongDeserializer.kt | 0 .../deserializers/UnsignedShortDeserializer.kt | 0 .../deserializers/X509CRLDeserializer.kt | 0 .../deserializers/X509CertificateDeserializer.kt | 0 .../serialization/deserializers/YearDeserializer.kt | 0 .../deserializers/YearMonthDeserializer.kt | 0 .../deserializers/ZoneIdDeserializer.kt | 0 .../deserializers/ZonedDateTimeDeserializer.kt | 0 .../src/main/resources/META-INF/DJVM-preload | 0 .../djvm/serialization/AMQPSerializationScheme.kt | 0 .../djvm/serialization/DelegatingClassLoader.kt | 0 .../SandboxSerializerFactoryFactory.kt | 0 .../corda/djvm/serialization/SandboxWhitelist.kt | 0 .../net/corda/djvm/serialization/Serialization.kt | 0 .../serialization/serializers/ExceptionUtils.kt | 0 .../serializers/PrimitiveSerializer.kt | 0 .../serializers/SandboxBitSetSerializer.kt | 0 .../serializers/SandboxCertPathSerializer.kt | 0 .../serializers/SandboxCharacterSerializer.kt | 0 .../serializers/SandboxClassSerializer.kt | 0 .../serializers/SandboxCollectionSerializer.kt | 0 .../serializers/SandboxCurrencySerializer.kt | 0 .../serializers/SandboxDecimal128Serializer.kt | 0 .../serializers/SandboxDecimal32Serializer.kt | 0 .../serializers/SandboxDecimal64Serializer.kt | 0 .../serializers/SandboxDurationSerializer.kt | 0 .../serializers/SandboxEnumSerializer.kt | 0 .../serializers/SandboxEnumSetSerializer.kt | 0 .../serializers/SandboxInputStreamSerializer.kt | 0 .../serializers/SandboxInstantSerializer.kt | 0 .../serializers/SandboxLocalDateSerializer.kt | 0 .../serializers/SandboxLocalDateTimeSerializer.kt | 0 .../serializers/SandboxLocalTimeSerializer.kt | 0 .../serializers/SandboxMapSerializer.kt | 0 .../serializers/SandboxMonthDaySerializer.kt | 0 .../serializers/SandboxOffsetDateTimeSerializer.kt | 0 .../serializers/SandboxOffsetTimeSerializer.kt | 0 .../SandboxOpaqueBytesSubSequenceSerializer.kt | 0 .../serializers/SandboxOptionalSerializer.kt | 0 .../serializers/SandboxPeriodSerializer.kt | 0 .../serializers/SandboxPrimitiveSerializer.kt | 0 .../serializers/SandboxPublicKeySerializer.kt | 0 .../serializers/SandboxSymbolSerializer.kt | 0 .../serializers/SandboxToStringSerializer.kt | 0 .../serializers/SandboxUnsignedByteSerializer.kt | 0 .../serializers/SandboxUnsignedIntegerSerializer.kt | 0 .../serializers/SandboxUnsignedLongSerializer.kt | 0 .../serializers/SandboxUnsignedShortSerializer.kt | 0 .../serializers/SandboxX509CRLSerializer.kt | 0 .../serializers/SandboxX509CertificateSerializer.kt | 0 .../serializers/SandboxYearMonthSerializer.kt | 0 .../serializers/SandboxYearSerializer.kt | 0 .../serializers/SandboxZoneIdSerializer.kt | 0 .../serializers/SandboxZonedDateTimeSerializer.kt | 0 .../src}/test/java/greymalkin/ExternalData.java | 0 .../src}/test/java/greymalkin/ExternalEnum.java | 0 .../net/corda/djvm/serialization/InnocentData.java | 0 .../djvm/serialization/MultiConstructorData.java | 0 .../net/corda/djvm/serialization/VeryEvilData.java | 0 .../djvm/serialization/DeserializeBigDecimalTest.kt | 0 .../djvm/serialization/DeserializeBigIntegerTest.kt | 0 .../djvm/serialization/DeserializeBitSetTest.kt | 0 .../serialization/DeserializeCertificatesTest.kt | 0 .../djvm/serialization/DeserializeClassTest.kt | 0 .../serialization/DeserializeCollectionsTest.kt | 0 .../djvm/serialization/DeserializeCurrencyTest.kt | 0 .../djvm/serialization/DeserializeEnumSetTest.kt | 0 .../corda/djvm/serialization/DeserializeEnumTest.kt | 0 .../djvm/serialization/DeserializeGenericsTest.kt | 0 .../serialization/DeserializeInputStreamTest.kt | 0 .../djvm/serialization/DeserializeInstantTest.kt | 0 .../DeserializeJavaWithMultipleConstructorsTest.kt | 0 .../serialization/DeserializeKotlinAliasTest.kt | 0 .../djvm/serialization/DeserializeLocalDateTest.kt | 0 .../serialization/DeserializeLocalDateTimeTest.kt | 0 .../djvm/serialization/DeserializeLocalTimeTest.kt | 0 .../corda/djvm/serialization/DeserializeMapsTest.kt | 0 .../djvm/serialization/DeserializeMonthDayTest.kt | 0 .../serialization/DeserializeObjectArraysTest.kt | 0 .../serialization/DeserializeOffsetDateTimeTest.kt | 0 .../djvm/serialization/DeserializeOffsetTimeTest.kt | 0 .../DeserializeOpaqueBytesSubSequenceTest.kt | 0 .../djvm/serialization/DeserializeOptionalTest.kt | 0 .../djvm/serialization/DeserializePeriodTest.kt | 0 .../serialization/DeserializePrimitiveArraysTest.kt | 0 .../djvm/serialization/DeserializePrimitivesTest.kt | 0 .../djvm/serialization/DeserializeProtonJTest.kt | 0 .../djvm/serialization/DeserializePublicKeyTest.kt | 0 .../serialization/DeserializeStringBufferTest.kt | 0 .../djvm/serialization/DeserializeStringTest.kt | 0 .../djvm/serialization/DeserializeYearMonthTest.kt | 0 .../corda/djvm/serialization/DeserializeYearTest.kt | 0 .../djvm/serialization/DeserializeZoneIdTest.kt | 0 .../serialization/DeserializeZonedDateTimeTest.kt | 0 .../corda/djvm/serialization/LocalSerialization.kt | 0 .../djvm/serialization/SafeDeserialisationTest.kt | 0 .../net/corda/djvm/serialization/SandboxType.kt | 0 .../kotlin/net/corda/djvm/serialization/TestBase.kt | 0 .../src}/test/resources/log4j2-test.xml | 0 .../src}/test/resources/testing.cert | Bin .../src}/test/scripts/generate-certificate.sh | 0 132 files changed, 0 insertions(+), 0 deletions(-) rename build.gradle => serialization-djvm/build.gradle (100%) rename {deserializers => serialization-djvm/deserializers}/build.gradle (100%) rename {deserializers => serialization-djvm/deserializers}/src/main/kotlin/net/corda/djvm/serialization/deserializers/BitSetDeserializer.kt (100%) rename {deserializers => serialization-djvm/deserializers}/src/main/kotlin/net/corda/djvm/serialization/deserializers/CertPathDeserializer.kt (100%) rename {deserializers => serialization-djvm/deserializers}/src/main/kotlin/net/corda/djvm/serialization/deserializers/ClassDeserializer.kt (100%) rename {deserializers => serialization-djvm/deserializers}/src/main/kotlin/net/corda/djvm/serialization/deserializers/CreateCollection.kt (100%) rename {deserializers => serialization-djvm/deserializers}/src/main/kotlin/net/corda/djvm/serialization/deserializers/CreateCurrency.kt (100%) rename {deserializers => serialization-djvm/deserializers}/src/main/kotlin/net/corda/djvm/serialization/deserializers/CreateFromString.kt (100%) rename {deserializers => serialization-djvm/deserializers}/src/main/kotlin/net/corda/djvm/serialization/deserializers/CreateMap.kt (100%) rename {deserializers => serialization-djvm/deserializers}/src/main/kotlin/net/corda/djvm/serialization/deserializers/Decimal128Deserializer.kt (100%) rename {deserializers => serialization-djvm/deserializers}/src/main/kotlin/net/corda/djvm/serialization/deserializers/Decimal32Deserializer.kt (100%) rename {deserializers => serialization-djvm/deserializers}/src/main/kotlin/net/corda/djvm/serialization/deserializers/Decimal64Deserializer.kt (100%) rename {deserializers => serialization-djvm/deserializers}/src/main/kotlin/net/corda/djvm/serialization/deserializers/DescribeEnum.kt (100%) rename {deserializers => serialization-djvm/deserializers}/src/main/kotlin/net/corda/djvm/serialization/deserializers/DurationDeserializer.kt (100%) rename {deserializers => serialization-djvm/deserializers}/src/main/kotlin/net/corda/djvm/serialization/deserializers/EnumSetDeserializer.kt (100%) rename {deserializers => serialization-djvm/deserializers}/src/main/kotlin/net/corda/djvm/serialization/deserializers/InputStreamDeserializer.kt (100%) rename {deserializers => serialization-djvm/deserializers}/src/main/kotlin/net/corda/djvm/serialization/deserializers/InstantDeserializer.kt (100%) rename {deserializers => serialization-djvm/deserializers}/src/main/kotlin/net/corda/djvm/serialization/deserializers/JustForCasting.kt (100%) rename {deserializers => serialization-djvm/deserializers}/src/main/kotlin/net/corda/djvm/serialization/deserializers/LocalDateDeserializer.kt (100%) rename {deserializers => serialization-djvm/deserializers}/src/main/kotlin/net/corda/djvm/serialization/deserializers/LocalDateTimeDeserializer.kt (100%) rename {deserializers => serialization-djvm/deserializers}/src/main/kotlin/net/corda/djvm/serialization/deserializers/LocalTimeDeserializer.kt (100%) rename {deserializers => serialization-djvm/deserializers}/src/main/kotlin/net/corda/djvm/serialization/deserializers/MonthDayDeserializer.kt (100%) rename {deserializers => serialization-djvm/deserializers}/src/main/kotlin/net/corda/djvm/serialization/deserializers/OffsetDateTimeDeserializer.kt (100%) rename {deserializers => serialization-djvm/deserializers}/src/main/kotlin/net/corda/djvm/serialization/deserializers/OffsetTimeDeserializer.kt (100%) rename {deserializers => serialization-djvm/deserializers}/src/main/kotlin/net/corda/djvm/serialization/deserializers/OpaqueBytesSubSequenceDeserializer.kt (100%) rename {deserializers => serialization-djvm/deserializers}/src/main/kotlin/net/corda/djvm/serialization/deserializers/OptionalDeserializer.kt (100%) rename {deserializers => serialization-djvm/deserializers}/src/main/kotlin/net/corda/djvm/serialization/deserializers/PeriodDeserializer.kt (100%) rename {deserializers => serialization-djvm/deserializers}/src/main/kotlin/net/corda/djvm/serialization/deserializers/PublicKeyDecoder.kt (100%) rename {deserializers => serialization-djvm/deserializers}/src/main/kotlin/net/corda/djvm/serialization/deserializers/SymbolDeserializer.kt (100%) rename {deserializers => serialization-djvm/deserializers}/src/main/kotlin/net/corda/djvm/serialization/deserializers/UnsignedByteDeserializer.kt (100%) rename {deserializers => serialization-djvm/deserializers}/src/main/kotlin/net/corda/djvm/serialization/deserializers/UnsignedIntegerDeserializer.kt (100%) rename {deserializers => serialization-djvm/deserializers}/src/main/kotlin/net/corda/djvm/serialization/deserializers/UnsignedLongDeserializer.kt (100%) rename {deserializers => serialization-djvm/deserializers}/src/main/kotlin/net/corda/djvm/serialization/deserializers/UnsignedShortDeserializer.kt (100%) rename {deserializers => serialization-djvm/deserializers}/src/main/kotlin/net/corda/djvm/serialization/deserializers/X509CRLDeserializer.kt (100%) rename {deserializers => serialization-djvm/deserializers}/src/main/kotlin/net/corda/djvm/serialization/deserializers/X509CertificateDeserializer.kt (100%) rename {deserializers => serialization-djvm/deserializers}/src/main/kotlin/net/corda/djvm/serialization/deserializers/YearDeserializer.kt (100%) rename {deserializers => serialization-djvm/deserializers}/src/main/kotlin/net/corda/djvm/serialization/deserializers/YearMonthDeserializer.kt (100%) rename {deserializers => serialization-djvm/deserializers}/src/main/kotlin/net/corda/djvm/serialization/deserializers/ZoneIdDeserializer.kt (100%) rename {deserializers => serialization-djvm/deserializers}/src/main/kotlin/net/corda/djvm/serialization/deserializers/ZonedDateTimeDeserializer.kt (100%) rename {deserializers => serialization-djvm/deserializers}/src/main/resources/META-INF/DJVM-preload (100%) rename {src => serialization-djvm/src}/main/kotlin/net/corda/djvm/serialization/AMQPSerializationScheme.kt (100%) rename {src => serialization-djvm/src}/main/kotlin/net/corda/djvm/serialization/DelegatingClassLoader.kt (100%) rename {src => serialization-djvm/src}/main/kotlin/net/corda/djvm/serialization/SandboxSerializerFactoryFactory.kt (100%) rename {src => serialization-djvm/src}/main/kotlin/net/corda/djvm/serialization/SandboxWhitelist.kt (100%) rename {src => serialization-djvm/src}/main/kotlin/net/corda/djvm/serialization/Serialization.kt (100%) rename {src => serialization-djvm/src}/main/kotlin/net/corda/djvm/serialization/serializers/ExceptionUtils.kt (100%) rename {src => serialization-djvm/src}/main/kotlin/net/corda/djvm/serialization/serializers/PrimitiveSerializer.kt (100%) rename {src => serialization-djvm/src}/main/kotlin/net/corda/djvm/serialization/serializers/SandboxBitSetSerializer.kt (100%) rename {src => serialization-djvm/src}/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCertPathSerializer.kt (100%) rename {src => serialization-djvm/src}/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCharacterSerializer.kt (100%) rename {src => serialization-djvm/src}/main/kotlin/net/corda/djvm/serialization/serializers/SandboxClassSerializer.kt (100%) rename {src => serialization-djvm/src}/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCollectionSerializer.kt (100%) rename {src => serialization-djvm/src}/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCurrencySerializer.kt (100%) rename {src => serialization-djvm/src}/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDecimal128Serializer.kt (100%) rename {src => serialization-djvm/src}/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDecimal32Serializer.kt (100%) rename {src => serialization-djvm/src}/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDecimal64Serializer.kt (100%) rename {src => serialization-djvm/src}/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDurationSerializer.kt (100%) rename {src => serialization-djvm/src}/main/kotlin/net/corda/djvm/serialization/serializers/SandboxEnumSerializer.kt (100%) rename {src => serialization-djvm/src}/main/kotlin/net/corda/djvm/serialization/serializers/SandboxEnumSetSerializer.kt (100%) rename {src => serialization-djvm/src}/main/kotlin/net/corda/djvm/serialization/serializers/SandboxInputStreamSerializer.kt (100%) rename {src => serialization-djvm/src}/main/kotlin/net/corda/djvm/serialization/serializers/SandboxInstantSerializer.kt (100%) rename {src => serialization-djvm/src}/main/kotlin/net/corda/djvm/serialization/serializers/SandboxLocalDateSerializer.kt (100%) rename {src => serialization-djvm/src}/main/kotlin/net/corda/djvm/serialization/serializers/SandboxLocalDateTimeSerializer.kt (100%) rename {src => serialization-djvm/src}/main/kotlin/net/corda/djvm/serialization/serializers/SandboxLocalTimeSerializer.kt (100%) rename {src => serialization-djvm/src}/main/kotlin/net/corda/djvm/serialization/serializers/SandboxMapSerializer.kt (100%) rename {src => serialization-djvm/src}/main/kotlin/net/corda/djvm/serialization/serializers/SandboxMonthDaySerializer.kt (100%) rename {src => serialization-djvm/src}/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOffsetDateTimeSerializer.kt (100%) rename {src => serialization-djvm/src}/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOffsetTimeSerializer.kt (100%) rename {src => serialization-djvm/src}/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOpaqueBytesSubSequenceSerializer.kt (100%) rename {src => serialization-djvm/src}/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOptionalSerializer.kt (100%) rename {src => serialization-djvm/src}/main/kotlin/net/corda/djvm/serialization/serializers/SandboxPeriodSerializer.kt (100%) rename {src => serialization-djvm/src}/main/kotlin/net/corda/djvm/serialization/serializers/SandboxPrimitiveSerializer.kt (100%) rename {src => serialization-djvm/src}/main/kotlin/net/corda/djvm/serialization/serializers/SandboxPublicKeySerializer.kt (100%) rename {src => serialization-djvm/src}/main/kotlin/net/corda/djvm/serialization/serializers/SandboxSymbolSerializer.kt (100%) rename {src => serialization-djvm/src}/main/kotlin/net/corda/djvm/serialization/serializers/SandboxToStringSerializer.kt (100%) rename {src => serialization-djvm/src}/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedByteSerializer.kt (100%) rename {src => serialization-djvm/src}/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedIntegerSerializer.kt (100%) rename {src => serialization-djvm/src}/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedLongSerializer.kt (100%) rename {src => serialization-djvm/src}/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedShortSerializer.kt (100%) rename {src => serialization-djvm/src}/main/kotlin/net/corda/djvm/serialization/serializers/SandboxX509CRLSerializer.kt (100%) rename {src => serialization-djvm/src}/main/kotlin/net/corda/djvm/serialization/serializers/SandboxX509CertificateSerializer.kt (100%) rename {src => serialization-djvm/src}/main/kotlin/net/corda/djvm/serialization/serializers/SandboxYearMonthSerializer.kt (100%) rename {src => serialization-djvm/src}/main/kotlin/net/corda/djvm/serialization/serializers/SandboxYearSerializer.kt (100%) rename {src => serialization-djvm/src}/main/kotlin/net/corda/djvm/serialization/serializers/SandboxZoneIdSerializer.kt (100%) rename {src => serialization-djvm/src}/main/kotlin/net/corda/djvm/serialization/serializers/SandboxZonedDateTimeSerializer.kt (100%) rename {src => serialization-djvm/src}/test/java/greymalkin/ExternalData.java (100%) rename {src => serialization-djvm/src}/test/java/greymalkin/ExternalEnum.java (100%) rename {src => serialization-djvm/src}/test/java/net/corda/djvm/serialization/InnocentData.java (100%) rename {src => serialization-djvm/src}/test/java/net/corda/djvm/serialization/MultiConstructorData.java (100%) rename {src => serialization-djvm/src}/test/java/net/corda/djvm/serialization/VeryEvilData.java (100%) rename {src => serialization-djvm/src}/test/kotlin/net/corda/djvm/serialization/DeserializeBigDecimalTest.kt (100%) rename {src => serialization-djvm/src}/test/kotlin/net/corda/djvm/serialization/DeserializeBigIntegerTest.kt (100%) rename {src => serialization-djvm/src}/test/kotlin/net/corda/djvm/serialization/DeserializeBitSetTest.kt (100%) rename {src => serialization-djvm/src}/test/kotlin/net/corda/djvm/serialization/DeserializeCertificatesTest.kt (100%) rename {src => serialization-djvm/src}/test/kotlin/net/corda/djvm/serialization/DeserializeClassTest.kt (100%) rename {src => serialization-djvm/src}/test/kotlin/net/corda/djvm/serialization/DeserializeCollectionsTest.kt (100%) rename {src => serialization-djvm/src}/test/kotlin/net/corda/djvm/serialization/DeserializeCurrencyTest.kt (100%) rename {src => serialization-djvm/src}/test/kotlin/net/corda/djvm/serialization/DeserializeEnumSetTest.kt (100%) rename {src => serialization-djvm/src}/test/kotlin/net/corda/djvm/serialization/DeserializeEnumTest.kt (100%) rename {src => serialization-djvm/src}/test/kotlin/net/corda/djvm/serialization/DeserializeGenericsTest.kt (100%) rename {src => serialization-djvm/src}/test/kotlin/net/corda/djvm/serialization/DeserializeInputStreamTest.kt (100%) rename {src => serialization-djvm/src}/test/kotlin/net/corda/djvm/serialization/DeserializeInstantTest.kt (100%) rename {src => serialization-djvm/src}/test/kotlin/net/corda/djvm/serialization/DeserializeJavaWithMultipleConstructorsTest.kt (100%) rename {src => serialization-djvm/src}/test/kotlin/net/corda/djvm/serialization/DeserializeKotlinAliasTest.kt (100%) rename {src => serialization-djvm/src}/test/kotlin/net/corda/djvm/serialization/DeserializeLocalDateTest.kt (100%) rename {src => serialization-djvm/src}/test/kotlin/net/corda/djvm/serialization/DeserializeLocalDateTimeTest.kt (100%) rename {src => serialization-djvm/src}/test/kotlin/net/corda/djvm/serialization/DeserializeLocalTimeTest.kt (100%) rename {src => serialization-djvm/src}/test/kotlin/net/corda/djvm/serialization/DeserializeMapsTest.kt (100%) rename {src => serialization-djvm/src}/test/kotlin/net/corda/djvm/serialization/DeserializeMonthDayTest.kt (100%) rename {src => serialization-djvm/src}/test/kotlin/net/corda/djvm/serialization/DeserializeObjectArraysTest.kt (100%) rename {src => serialization-djvm/src}/test/kotlin/net/corda/djvm/serialization/DeserializeOffsetDateTimeTest.kt (100%) rename {src => serialization-djvm/src}/test/kotlin/net/corda/djvm/serialization/DeserializeOffsetTimeTest.kt (100%) rename {src => serialization-djvm/src}/test/kotlin/net/corda/djvm/serialization/DeserializeOpaqueBytesSubSequenceTest.kt (100%) rename {src => serialization-djvm/src}/test/kotlin/net/corda/djvm/serialization/DeserializeOptionalTest.kt (100%) rename {src => serialization-djvm/src}/test/kotlin/net/corda/djvm/serialization/DeserializePeriodTest.kt (100%) rename {src => serialization-djvm/src}/test/kotlin/net/corda/djvm/serialization/DeserializePrimitiveArraysTest.kt (100%) rename {src => serialization-djvm/src}/test/kotlin/net/corda/djvm/serialization/DeserializePrimitivesTest.kt (100%) rename {src => serialization-djvm/src}/test/kotlin/net/corda/djvm/serialization/DeserializeProtonJTest.kt (100%) rename {src => serialization-djvm/src}/test/kotlin/net/corda/djvm/serialization/DeserializePublicKeyTest.kt (100%) rename {src => serialization-djvm/src}/test/kotlin/net/corda/djvm/serialization/DeserializeStringBufferTest.kt (100%) rename {src => serialization-djvm/src}/test/kotlin/net/corda/djvm/serialization/DeserializeStringTest.kt (100%) rename {src => serialization-djvm/src}/test/kotlin/net/corda/djvm/serialization/DeserializeYearMonthTest.kt (100%) rename {src => serialization-djvm/src}/test/kotlin/net/corda/djvm/serialization/DeserializeYearTest.kt (100%) rename {src => serialization-djvm/src}/test/kotlin/net/corda/djvm/serialization/DeserializeZoneIdTest.kt (100%) rename {src => serialization-djvm/src}/test/kotlin/net/corda/djvm/serialization/DeserializeZonedDateTimeTest.kt (100%) rename {src => serialization-djvm/src}/test/kotlin/net/corda/djvm/serialization/LocalSerialization.kt (100%) rename {src => serialization-djvm/src}/test/kotlin/net/corda/djvm/serialization/SafeDeserialisationTest.kt (100%) rename {src => serialization-djvm/src}/test/kotlin/net/corda/djvm/serialization/SandboxType.kt (100%) rename {src => serialization-djvm/src}/test/kotlin/net/corda/djvm/serialization/TestBase.kt (100%) rename {src => serialization-djvm/src}/test/resources/log4j2-test.xml (100%) rename {src => serialization-djvm/src}/test/resources/testing.cert (100%) rename {src => serialization-djvm/src}/test/scripts/generate-certificate.sh (100%) diff --git a/build.gradle b/serialization-djvm/build.gradle similarity index 100% rename from build.gradle rename to serialization-djvm/build.gradle diff --git a/deserializers/build.gradle b/serialization-djvm/deserializers/build.gradle similarity index 100% rename from deserializers/build.gradle rename to serialization-djvm/deserializers/build.gradle diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/BitSetDeserializer.kt b/serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/BitSetDeserializer.kt similarity index 100% rename from deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/BitSetDeserializer.kt rename to serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/BitSetDeserializer.kt diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/CertPathDeserializer.kt b/serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/CertPathDeserializer.kt similarity index 100% rename from deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/CertPathDeserializer.kt rename to serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/CertPathDeserializer.kt diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/ClassDeserializer.kt b/serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/ClassDeserializer.kt similarity index 100% rename from deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/ClassDeserializer.kt rename to serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/ClassDeserializer.kt diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/CreateCollection.kt b/serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/CreateCollection.kt similarity index 100% rename from deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/CreateCollection.kt rename to serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/CreateCollection.kt diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/CreateCurrency.kt b/serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/CreateCurrency.kt similarity index 100% rename from deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/CreateCurrency.kt rename to serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/CreateCurrency.kt diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/CreateFromString.kt b/serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/CreateFromString.kt similarity index 100% rename from deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/CreateFromString.kt rename to serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/CreateFromString.kt diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/CreateMap.kt b/serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/CreateMap.kt similarity index 100% rename from deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/CreateMap.kt rename to serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/CreateMap.kt diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/Decimal128Deserializer.kt b/serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/Decimal128Deserializer.kt similarity index 100% rename from deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/Decimal128Deserializer.kt rename to serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/Decimal128Deserializer.kt diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/Decimal32Deserializer.kt b/serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/Decimal32Deserializer.kt similarity index 100% rename from deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/Decimal32Deserializer.kt rename to serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/Decimal32Deserializer.kt diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/Decimal64Deserializer.kt b/serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/Decimal64Deserializer.kt similarity index 100% rename from deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/Decimal64Deserializer.kt rename to serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/Decimal64Deserializer.kt diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/DescribeEnum.kt b/serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/DescribeEnum.kt similarity index 100% rename from deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/DescribeEnum.kt rename to serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/DescribeEnum.kt diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/DurationDeserializer.kt b/serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/DurationDeserializer.kt similarity index 100% rename from deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/DurationDeserializer.kt rename to serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/DurationDeserializer.kt diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/EnumSetDeserializer.kt b/serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/EnumSetDeserializer.kt similarity index 100% rename from deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/EnumSetDeserializer.kt rename to serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/EnumSetDeserializer.kt diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/InputStreamDeserializer.kt b/serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/InputStreamDeserializer.kt similarity index 100% rename from deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/InputStreamDeserializer.kt rename to serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/InputStreamDeserializer.kt diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/InstantDeserializer.kt b/serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/InstantDeserializer.kt similarity index 100% rename from deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/InstantDeserializer.kt rename to serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/InstantDeserializer.kt diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/JustForCasting.kt b/serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/JustForCasting.kt similarity index 100% rename from deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/JustForCasting.kt rename to serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/JustForCasting.kt diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/LocalDateDeserializer.kt b/serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/LocalDateDeserializer.kt similarity index 100% rename from deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/LocalDateDeserializer.kt rename to serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/LocalDateDeserializer.kt diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/LocalDateTimeDeserializer.kt b/serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/LocalDateTimeDeserializer.kt similarity index 100% rename from deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/LocalDateTimeDeserializer.kt rename to serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/LocalDateTimeDeserializer.kt diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/LocalTimeDeserializer.kt b/serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/LocalTimeDeserializer.kt similarity index 100% rename from deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/LocalTimeDeserializer.kt rename to serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/LocalTimeDeserializer.kt diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/MonthDayDeserializer.kt b/serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/MonthDayDeserializer.kt similarity index 100% rename from deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/MonthDayDeserializer.kt rename to serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/MonthDayDeserializer.kt diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/OffsetDateTimeDeserializer.kt b/serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/OffsetDateTimeDeserializer.kt similarity index 100% rename from deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/OffsetDateTimeDeserializer.kt rename to serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/OffsetDateTimeDeserializer.kt diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/OffsetTimeDeserializer.kt b/serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/OffsetTimeDeserializer.kt similarity index 100% rename from deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/OffsetTimeDeserializer.kt rename to serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/OffsetTimeDeserializer.kt diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/OpaqueBytesSubSequenceDeserializer.kt b/serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/OpaqueBytesSubSequenceDeserializer.kt similarity index 100% rename from deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/OpaqueBytesSubSequenceDeserializer.kt rename to serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/OpaqueBytesSubSequenceDeserializer.kt diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/OptionalDeserializer.kt b/serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/OptionalDeserializer.kt similarity index 100% rename from deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/OptionalDeserializer.kt rename to serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/OptionalDeserializer.kt diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/PeriodDeserializer.kt b/serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/PeriodDeserializer.kt similarity index 100% rename from deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/PeriodDeserializer.kt rename to serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/PeriodDeserializer.kt diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/PublicKeyDecoder.kt b/serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/PublicKeyDecoder.kt similarity index 100% rename from deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/PublicKeyDecoder.kt rename to serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/PublicKeyDecoder.kt diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/SymbolDeserializer.kt b/serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/SymbolDeserializer.kt similarity index 100% rename from deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/SymbolDeserializer.kt rename to serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/SymbolDeserializer.kt diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/UnsignedByteDeserializer.kt b/serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/UnsignedByteDeserializer.kt similarity index 100% rename from deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/UnsignedByteDeserializer.kt rename to serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/UnsignedByteDeserializer.kt diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/UnsignedIntegerDeserializer.kt b/serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/UnsignedIntegerDeserializer.kt similarity index 100% rename from deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/UnsignedIntegerDeserializer.kt rename to serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/UnsignedIntegerDeserializer.kt diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/UnsignedLongDeserializer.kt b/serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/UnsignedLongDeserializer.kt similarity index 100% rename from deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/UnsignedLongDeserializer.kt rename to serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/UnsignedLongDeserializer.kt diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/UnsignedShortDeserializer.kt b/serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/UnsignedShortDeserializer.kt similarity index 100% rename from deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/UnsignedShortDeserializer.kt rename to serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/UnsignedShortDeserializer.kt diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/X509CRLDeserializer.kt b/serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/X509CRLDeserializer.kt similarity index 100% rename from deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/X509CRLDeserializer.kt rename to serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/X509CRLDeserializer.kt diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/X509CertificateDeserializer.kt b/serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/X509CertificateDeserializer.kt similarity index 100% rename from deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/X509CertificateDeserializer.kt rename to serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/X509CertificateDeserializer.kt diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/YearDeserializer.kt b/serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/YearDeserializer.kt similarity index 100% rename from deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/YearDeserializer.kt rename to serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/YearDeserializer.kt diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/YearMonthDeserializer.kt b/serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/YearMonthDeserializer.kt similarity index 100% rename from deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/YearMonthDeserializer.kt rename to serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/YearMonthDeserializer.kt diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/ZoneIdDeserializer.kt b/serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/ZoneIdDeserializer.kt similarity index 100% rename from deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/ZoneIdDeserializer.kt rename to serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/ZoneIdDeserializer.kt diff --git a/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/ZonedDateTimeDeserializer.kt b/serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/ZonedDateTimeDeserializer.kt similarity index 100% rename from deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/ZonedDateTimeDeserializer.kt rename to serialization-djvm/deserializers/src/main/kotlin/net/corda/djvm/serialization/deserializers/ZonedDateTimeDeserializer.kt diff --git a/deserializers/src/main/resources/META-INF/DJVM-preload b/serialization-djvm/deserializers/src/main/resources/META-INF/DJVM-preload similarity index 100% rename from deserializers/src/main/resources/META-INF/DJVM-preload rename to serialization-djvm/deserializers/src/main/resources/META-INF/DJVM-preload diff --git a/src/main/kotlin/net/corda/djvm/serialization/AMQPSerializationScheme.kt b/serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/AMQPSerializationScheme.kt similarity index 100% rename from src/main/kotlin/net/corda/djvm/serialization/AMQPSerializationScheme.kt rename to serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/AMQPSerializationScheme.kt diff --git a/src/main/kotlin/net/corda/djvm/serialization/DelegatingClassLoader.kt b/serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/DelegatingClassLoader.kt similarity index 100% rename from src/main/kotlin/net/corda/djvm/serialization/DelegatingClassLoader.kt rename to serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/DelegatingClassLoader.kt diff --git a/src/main/kotlin/net/corda/djvm/serialization/SandboxSerializerFactoryFactory.kt b/serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/SandboxSerializerFactoryFactory.kt similarity index 100% rename from src/main/kotlin/net/corda/djvm/serialization/SandboxSerializerFactoryFactory.kt rename to serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/SandboxSerializerFactoryFactory.kt diff --git a/src/main/kotlin/net/corda/djvm/serialization/SandboxWhitelist.kt b/serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/SandboxWhitelist.kt similarity index 100% rename from src/main/kotlin/net/corda/djvm/serialization/SandboxWhitelist.kt rename to serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/SandboxWhitelist.kt diff --git a/src/main/kotlin/net/corda/djvm/serialization/Serialization.kt b/serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/Serialization.kt similarity index 100% rename from src/main/kotlin/net/corda/djvm/serialization/Serialization.kt rename to serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/Serialization.kt diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/ExceptionUtils.kt b/serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/ExceptionUtils.kt similarity index 100% rename from src/main/kotlin/net/corda/djvm/serialization/serializers/ExceptionUtils.kt rename to serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/ExceptionUtils.kt diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/PrimitiveSerializer.kt b/serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/PrimitiveSerializer.kt similarity index 100% rename from src/main/kotlin/net/corda/djvm/serialization/serializers/PrimitiveSerializer.kt rename to serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/PrimitiveSerializer.kt diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxBitSetSerializer.kt b/serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxBitSetSerializer.kt similarity index 100% rename from src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxBitSetSerializer.kt rename to serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxBitSetSerializer.kt diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCertPathSerializer.kt b/serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCertPathSerializer.kt similarity index 100% rename from src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCertPathSerializer.kt rename to serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCertPathSerializer.kt diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCharacterSerializer.kt b/serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCharacterSerializer.kt similarity index 100% rename from src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCharacterSerializer.kt rename to serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCharacterSerializer.kt diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxClassSerializer.kt b/serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxClassSerializer.kt similarity index 100% rename from src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxClassSerializer.kt rename to serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxClassSerializer.kt diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCollectionSerializer.kt b/serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCollectionSerializer.kt similarity index 100% rename from src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCollectionSerializer.kt rename to serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCollectionSerializer.kt diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCurrencySerializer.kt b/serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCurrencySerializer.kt similarity index 100% rename from src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCurrencySerializer.kt rename to serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCurrencySerializer.kt diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDecimal128Serializer.kt b/serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDecimal128Serializer.kt similarity index 100% rename from src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDecimal128Serializer.kt rename to serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDecimal128Serializer.kt diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDecimal32Serializer.kt b/serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDecimal32Serializer.kt similarity index 100% rename from src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDecimal32Serializer.kt rename to serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDecimal32Serializer.kt diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDecimal64Serializer.kt b/serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDecimal64Serializer.kt similarity index 100% rename from src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDecimal64Serializer.kt rename to serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDecimal64Serializer.kt diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDurationSerializer.kt b/serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDurationSerializer.kt similarity index 100% rename from src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDurationSerializer.kt rename to serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDurationSerializer.kt diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxEnumSerializer.kt b/serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxEnumSerializer.kt similarity index 100% rename from src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxEnumSerializer.kt rename to serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxEnumSerializer.kt diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxEnumSetSerializer.kt b/serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxEnumSetSerializer.kt similarity index 100% rename from src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxEnumSetSerializer.kt rename to serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxEnumSetSerializer.kt diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxInputStreamSerializer.kt b/serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxInputStreamSerializer.kt similarity index 100% rename from src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxInputStreamSerializer.kt rename to serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxInputStreamSerializer.kt diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxInstantSerializer.kt b/serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxInstantSerializer.kt similarity index 100% rename from src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxInstantSerializer.kt rename to serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxInstantSerializer.kt diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxLocalDateSerializer.kt b/serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxLocalDateSerializer.kt similarity index 100% rename from src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxLocalDateSerializer.kt rename to serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxLocalDateSerializer.kt diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxLocalDateTimeSerializer.kt b/serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxLocalDateTimeSerializer.kt similarity index 100% rename from src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxLocalDateTimeSerializer.kt rename to serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxLocalDateTimeSerializer.kt diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxLocalTimeSerializer.kt b/serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxLocalTimeSerializer.kt similarity index 100% rename from src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxLocalTimeSerializer.kt rename to serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxLocalTimeSerializer.kt diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxMapSerializer.kt b/serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxMapSerializer.kt similarity index 100% rename from src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxMapSerializer.kt rename to serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxMapSerializer.kt diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxMonthDaySerializer.kt b/serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxMonthDaySerializer.kt similarity index 100% rename from src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxMonthDaySerializer.kt rename to serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxMonthDaySerializer.kt diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOffsetDateTimeSerializer.kt b/serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOffsetDateTimeSerializer.kt similarity index 100% rename from src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOffsetDateTimeSerializer.kt rename to serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOffsetDateTimeSerializer.kt diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOffsetTimeSerializer.kt b/serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOffsetTimeSerializer.kt similarity index 100% rename from src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOffsetTimeSerializer.kt rename to serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOffsetTimeSerializer.kt diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOpaqueBytesSubSequenceSerializer.kt b/serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOpaqueBytesSubSequenceSerializer.kt similarity index 100% rename from src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOpaqueBytesSubSequenceSerializer.kt rename to serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOpaqueBytesSubSequenceSerializer.kt diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOptionalSerializer.kt b/serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOptionalSerializer.kt similarity index 100% rename from src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOptionalSerializer.kt rename to serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOptionalSerializer.kt diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxPeriodSerializer.kt b/serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxPeriodSerializer.kt similarity index 100% rename from src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxPeriodSerializer.kt rename to serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxPeriodSerializer.kt diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxPrimitiveSerializer.kt b/serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxPrimitiveSerializer.kt similarity index 100% rename from src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxPrimitiveSerializer.kt rename to serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxPrimitiveSerializer.kt diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxPublicKeySerializer.kt b/serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxPublicKeySerializer.kt similarity index 100% rename from src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxPublicKeySerializer.kt rename to serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxPublicKeySerializer.kt diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxSymbolSerializer.kt b/serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxSymbolSerializer.kt similarity index 100% rename from src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxSymbolSerializer.kt rename to serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxSymbolSerializer.kt diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxToStringSerializer.kt b/serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxToStringSerializer.kt similarity index 100% rename from src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxToStringSerializer.kt rename to serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxToStringSerializer.kt diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedByteSerializer.kt b/serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedByteSerializer.kt similarity index 100% rename from src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedByteSerializer.kt rename to serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedByteSerializer.kt diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedIntegerSerializer.kt b/serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedIntegerSerializer.kt similarity index 100% rename from src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedIntegerSerializer.kt rename to serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedIntegerSerializer.kt diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedLongSerializer.kt b/serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedLongSerializer.kt similarity index 100% rename from src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedLongSerializer.kt rename to serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedLongSerializer.kt diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedShortSerializer.kt b/serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedShortSerializer.kt similarity index 100% rename from src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedShortSerializer.kt rename to serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedShortSerializer.kt diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxX509CRLSerializer.kt b/serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxX509CRLSerializer.kt similarity index 100% rename from src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxX509CRLSerializer.kt rename to serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxX509CRLSerializer.kt diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxX509CertificateSerializer.kt b/serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxX509CertificateSerializer.kt similarity index 100% rename from src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxX509CertificateSerializer.kt rename to serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxX509CertificateSerializer.kt diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxYearMonthSerializer.kt b/serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxYearMonthSerializer.kt similarity index 100% rename from src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxYearMonthSerializer.kt rename to serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxYearMonthSerializer.kt diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxYearSerializer.kt b/serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxYearSerializer.kt similarity index 100% rename from src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxYearSerializer.kt rename to serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxYearSerializer.kt diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxZoneIdSerializer.kt b/serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxZoneIdSerializer.kt similarity index 100% rename from src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxZoneIdSerializer.kt rename to serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxZoneIdSerializer.kt diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxZonedDateTimeSerializer.kt b/serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxZonedDateTimeSerializer.kt similarity index 100% rename from src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxZonedDateTimeSerializer.kt rename to serialization-djvm/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxZonedDateTimeSerializer.kt diff --git a/src/test/java/greymalkin/ExternalData.java b/serialization-djvm/src/test/java/greymalkin/ExternalData.java similarity index 100% rename from src/test/java/greymalkin/ExternalData.java rename to serialization-djvm/src/test/java/greymalkin/ExternalData.java diff --git a/src/test/java/greymalkin/ExternalEnum.java b/serialization-djvm/src/test/java/greymalkin/ExternalEnum.java similarity index 100% rename from src/test/java/greymalkin/ExternalEnum.java rename to serialization-djvm/src/test/java/greymalkin/ExternalEnum.java diff --git a/src/test/java/net/corda/djvm/serialization/InnocentData.java b/serialization-djvm/src/test/java/net/corda/djvm/serialization/InnocentData.java similarity index 100% rename from src/test/java/net/corda/djvm/serialization/InnocentData.java rename to serialization-djvm/src/test/java/net/corda/djvm/serialization/InnocentData.java diff --git a/src/test/java/net/corda/djvm/serialization/MultiConstructorData.java b/serialization-djvm/src/test/java/net/corda/djvm/serialization/MultiConstructorData.java similarity index 100% rename from src/test/java/net/corda/djvm/serialization/MultiConstructorData.java rename to serialization-djvm/src/test/java/net/corda/djvm/serialization/MultiConstructorData.java diff --git a/src/test/java/net/corda/djvm/serialization/VeryEvilData.java b/serialization-djvm/src/test/java/net/corda/djvm/serialization/VeryEvilData.java similarity index 100% rename from src/test/java/net/corda/djvm/serialization/VeryEvilData.java rename to serialization-djvm/src/test/java/net/corda/djvm/serialization/VeryEvilData.java diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeBigDecimalTest.kt b/serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeBigDecimalTest.kt similarity index 100% rename from src/test/kotlin/net/corda/djvm/serialization/DeserializeBigDecimalTest.kt rename to serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeBigDecimalTest.kt diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeBigIntegerTest.kt b/serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeBigIntegerTest.kt similarity index 100% rename from src/test/kotlin/net/corda/djvm/serialization/DeserializeBigIntegerTest.kt rename to serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeBigIntegerTest.kt diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeBitSetTest.kt b/serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeBitSetTest.kt similarity index 100% rename from src/test/kotlin/net/corda/djvm/serialization/DeserializeBitSetTest.kt rename to serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeBitSetTest.kt diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeCertificatesTest.kt b/serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeCertificatesTest.kt similarity index 100% rename from src/test/kotlin/net/corda/djvm/serialization/DeserializeCertificatesTest.kt rename to serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeCertificatesTest.kt diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeClassTest.kt b/serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeClassTest.kt similarity index 100% rename from src/test/kotlin/net/corda/djvm/serialization/DeserializeClassTest.kt rename to serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeClassTest.kt diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeCollectionsTest.kt b/serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeCollectionsTest.kt similarity index 100% rename from src/test/kotlin/net/corda/djvm/serialization/DeserializeCollectionsTest.kt rename to serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeCollectionsTest.kt diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeCurrencyTest.kt b/serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeCurrencyTest.kt similarity index 100% rename from src/test/kotlin/net/corda/djvm/serialization/DeserializeCurrencyTest.kt rename to serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeCurrencyTest.kt diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeEnumSetTest.kt b/serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeEnumSetTest.kt similarity index 100% rename from src/test/kotlin/net/corda/djvm/serialization/DeserializeEnumSetTest.kt rename to serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeEnumSetTest.kt diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeEnumTest.kt b/serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeEnumTest.kt similarity index 100% rename from src/test/kotlin/net/corda/djvm/serialization/DeserializeEnumTest.kt rename to serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeEnumTest.kt diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeGenericsTest.kt b/serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeGenericsTest.kt similarity index 100% rename from src/test/kotlin/net/corda/djvm/serialization/DeserializeGenericsTest.kt rename to serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeGenericsTest.kt diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeInputStreamTest.kt b/serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeInputStreamTest.kt similarity index 100% rename from src/test/kotlin/net/corda/djvm/serialization/DeserializeInputStreamTest.kt rename to serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeInputStreamTest.kt diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeInstantTest.kt b/serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeInstantTest.kt similarity index 100% rename from src/test/kotlin/net/corda/djvm/serialization/DeserializeInstantTest.kt rename to serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeInstantTest.kt diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeJavaWithMultipleConstructorsTest.kt b/serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeJavaWithMultipleConstructorsTest.kt similarity index 100% rename from src/test/kotlin/net/corda/djvm/serialization/DeserializeJavaWithMultipleConstructorsTest.kt rename to serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeJavaWithMultipleConstructorsTest.kt diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeKotlinAliasTest.kt b/serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeKotlinAliasTest.kt similarity index 100% rename from src/test/kotlin/net/corda/djvm/serialization/DeserializeKotlinAliasTest.kt rename to serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeKotlinAliasTest.kt diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeLocalDateTest.kt b/serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeLocalDateTest.kt similarity index 100% rename from src/test/kotlin/net/corda/djvm/serialization/DeserializeLocalDateTest.kt rename to serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeLocalDateTest.kt diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeLocalDateTimeTest.kt b/serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeLocalDateTimeTest.kt similarity index 100% rename from src/test/kotlin/net/corda/djvm/serialization/DeserializeLocalDateTimeTest.kt rename to serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeLocalDateTimeTest.kt diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeLocalTimeTest.kt b/serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeLocalTimeTest.kt similarity index 100% rename from src/test/kotlin/net/corda/djvm/serialization/DeserializeLocalTimeTest.kt rename to serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeLocalTimeTest.kt diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeMapsTest.kt b/serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeMapsTest.kt similarity index 100% rename from src/test/kotlin/net/corda/djvm/serialization/DeserializeMapsTest.kt rename to serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeMapsTest.kt diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeMonthDayTest.kt b/serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeMonthDayTest.kt similarity index 100% rename from src/test/kotlin/net/corda/djvm/serialization/DeserializeMonthDayTest.kt rename to serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeMonthDayTest.kt diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeObjectArraysTest.kt b/serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeObjectArraysTest.kt similarity index 100% rename from src/test/kotlin/net/corda/djvm/serialization/DeserializeObjectArraysTest.kt rename to serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeObjectArraysTest.kt diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeOffsetDateTimeTest.kt b/serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeOffsetDateTimeTest.kt similarity index 100% rename from src/test/kotlin/net/corda/djvm/serialization/DeserializeOffsetDateTimeTest.kt rename to serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeOffsetDateTimeTest.kt diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeOffsetTimeTest.kt b/serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeOffsetTimeTest.kt similarity index 100% rename from src/test/kotlin/net/corda/djvm/serialization/DeserializeOffsetTimeTest.kt rename to serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeOffsetTimeTest.kt diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeOpaqueBytesSubSequenceTest.kt b/serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeOpaqueBytesSubSequenceTest.kt similarity index 100% rename from src/test/kotlin/net/corda/djvm/serialization/DeserializeOpaqueBytesSubSequenceTest.kt rename to serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeOpaqueBytesSubSequenceTest.kt diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeOptionalTest.kt b/serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeOptionalTest.kt similarity index 100% rename from src/test/kotlin/net/corda/djvm/serialization/DeserializeOptionalTest.kt rename to serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeOptionalTest.kt diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializePeriodTest.kt b/serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializePeriodTest.kt similarity index 100% rename from src/test/kotlin/net/corda/djvm/serialization/DeserializePeriodTest.kt rename to serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializePeriodTest.kt diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializePrimitiveArraysTest.kt b/serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializePrimitiveArraysTest.kt similarity index 100% rename from src/test/kotlin/net/corda/djvm/serialization/DeserializePrimitiveArraysTest.kt rename to serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializePrimitiveArraysTest.kt diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializePrimitivesTest.kt b/serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializePrimitivesTest.kt similarity index 100% rename from src/test/kotlin/net/corda/djvm/serialization/DeserializePrimitivesTest.kt rename to serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializePrimitivesTest.kt diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeProtonJTest.kt b/serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeProtonJTest.kt similarity index 100% rename from src/test/kotlin/net/corda/djvm/serialization/DeserializeProtonJTest.kt rename to serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeProtonJTest.kt diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializePublicKeyTest.kt b/serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializePublicKeyTest.kt similarity index 100% rename from src/test/kotlin/net/corda/djvm/serialization/DeserializePublicKeyTest.kt rename to serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializePublicKeyTest.kt diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeStringBufferTest.kt b/serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeStringBufferTest.kt similarity index 100% rename from src/test/kotlin/net/corda/djvm/serialization/DeserializeStringBufferTest.kt rename to serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeStringBufferTest.kt diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeStringTest.kt b/serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeStringTest.kt similarity index 100% rename from src/test/kotlin/net/corda/djvm/serialization/DeserializeStringTest.kt rename to serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeStringTest.kt diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeYearMonthTest.kt b/serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeYearMonthTest.kt similarity index 100% rename from src/test/kotlin/net/corda/djvm/serialization/DeserializeYearMonthTest.kt rename to serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeYearMonthTest.kt diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeYearTest.kt b/serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeYearTest.kt similarity index 100% rename from src/test/kotlin/net/corda/djvm/serialization/DeserializeYearTest.kt rename to serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeYearTest.kt diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeZoneIdTest.kt b/serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeZoneIdTest.kt similarity index 100% rename from src/test/kotlin/net/corda/djvm/serialization/DeserializeZoneIdTest.kt rename to serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeZoneIdTest.kt diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeZonedDateTimeTest.kt b/serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeZonedDateTimeTest.kt similarity index 100% rename from src/test/kotlin/net/corda/djvm/serialization/DeserializeZonedDateTimeTest.kt rename to serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/DeserializeZonedDateTimeTest.kt diff --git a/src/test/kotlin/net/corda/djvm/serialization/LocalSerialization.kt b/serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/LocalSerialization.kt similarity index 100% rename from src/test/kotlin/net/corda/djvm/serialization/LocalSerialization.kt rename to serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/LocalSerialization.kt diff --git a/src/test/kotlin/net/corda/djvm/serialization/SafeDeserialisationTest.kt b/serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/SafeDeserialisationTest.kt similarity index 100% rename from src/test/kotlin/net/corda/djvm/serialization/SafeDeserialisationTest.kt rename to serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/SafeDeserialisationTest.kt diff --git a/src/test/kotlin/net/corda/djvm/serialization/SandboxType.kt b/serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/SandboxType.kt similarity index 100% rename from src/test/kotlin/net/corda/djvm/serialization/SandboxType.kt rename to serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/SandboxType.kt diff --git a/src/test/kotlin/net/corda/djvm/serialization/TestBase.kt b/serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/TestBase.kt similarity index 100% rename from src/test/kotlin/net/corda/djvm/serialization/TestBase.kt rename to serialization-djvm/src/test/kotlin/net/corda/djvm/serialization/TestBase.kt diff --git a/src/test/resources/log4j2-test.xml b/serialization-djvm/src/test/resources/log4j2-test.xml similarity index 100% rename from src/test/resources/log4j2-test.xml rename to serialization-djvm/src/test/resources/log4j2-test.xml diff --git a/src/test/resources/testing.cert b/serialization-djvm/src/test/resources/testing.cert similarity index 100% rename from src/test/resources/testing.cert rename to serialization-djvm/src/test/resources/testing.cert diff --git a/src/test/scripts/generate-certificate.sh b/serialization-djvm/src/test/scripts/generate-certificate.sh similarity index 100% rename from src/test/scripts/generate-certificate.sh rename to serialization-djvm/src/test/scripts/generate-certificate.sh