Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(connector-corda): add JSON classname->JVM class object deserialize #3351

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ class JsonJvmObjectDeserializer(
val constructorArgs: Array<Any?> = jvmObject.jvmCtorArgs.map { x -> instantiate(x) }.toTypedArray()

when {
Class::class.java.isAssignableFrom(clazz) -> {
val x = constructorArgs.map { ca -> ca as String }.first()
return Class.forName(x)
}
DoubleArray::class.java.isAssignableFrom(clazz) -> {
return constructorArgs
.map { ca -> ca as Double }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,35 @@ enum class Direction {
NORTH, SOUTH, WEST, EAST
}

class TestTxData {}
class JsonJvmObjectDeserializerTest {

companion object {
val deserializer = JsonJvmObjectDeserializer()
}


@Test
fun classForNameHappyPath() {

val jvmObject = JvmObject(
jvmTypeKind = JvmTypeKind.REFERENCE,
jvmType = JvmType(
fqClassName = Class::class.java.name
),
jvmCtorArgs = listOf(
JvmObject(
jvmTypeKind = JvmTypeKind.PRIMITIVE,
jvmType = JvmType(String::class.java.name),
primitiveValue = TestTxData::class.java.name
)
)
)

val deserializedObject = deserializer.instantiate(jvmObject)

assert(deserializedObject == TestTxData::class.java)
}
@Test
fun enumHappyPath() {
val actual = Direction.WEST
Expand Down
Loading