mirror of
https://github.com/corda/corda.git
synced 2024-12-19 04:57:58 +00:00
CORDA-2227 Change ? to java.lang.Object in type notation for Any (#4380)
* Change ? to * in type notation for Any * Strings are atomic * Revert test
This commit is contained in:
parent
1f8582e99f
commit
6d9f03795e
@ -46,8 +46,8 @@ object AMQPTypeIdentifiers {
|
|||||||
fun nameForType(typeIdentifier: TypeIdentifier): String = when(typeIdentifier) {
|
fun nameForType(typeIdentifier: TypeIdentifier): String = when(typeIdentifier) {
|
||||||
is TypeIdentifier.Erased -> typeIdentifier.name
|
is TypeIdentifier.Erased -> typeIdentifier.name
|
||||||
is TypeIdentifier.Unparameterised -> primitiveTypeNamesByName[typeIdentifier] ?: typeIdentifier.name
|
is TypeIdentifier.Unparameterised -> primitiveTypeNamesByName[typeIdentifier] ?: typeIdentifier.name
|
||||||
is TypeIdentifier.UnknownType,
|
is TypeIdentifier.UnknownType -> "?"
|
||||||
is TypeIdentifier.TopType -> "?"
|
is TypeIdentifier.TopType -> TypeIdentifier.TopType.name
|
||||||
is TypeIdentifier.ArrayOf ->
|
is TypeIdentifier.ArrayOf ->
|
||||||
if (typeIdentifier == primitiveByteArrayType) "binary"
|
if (typeIdentifier == primitiveByteArrayType) "binary"
|
||||||
else nameForType(typeIdentifier.componentType) +
|
else nameForType(typeIdentifier.componentType) +
|
||||||
|
@ -103,7 +103,8 @@ internal data class LocalTypeInformationBuilder(val lookup: LocalTypeLookup,
|
|||||||
Collection::class.java.isAssignableFrom(type) &&
|
Collection::class.java.isAssignableFrom(type) &&
|
||||||
!EnumSet::class.java.isAssignableFrom(type) -> LocalTypeInformation.ACollection(type, typeIdentifier, LocalTypeInformation.Unknown)
|
!EnumSet::class.java.isAssignableFrom(type) -> LocalTypeInformation.ACollection(type, typeIdentifier, LocalTypeInformation.Unknown)
|
||||||
Map::class.java.isAssignableFrom(type) -> LocalTypeInformation.AMap(type, typeIdentifier, LocalTypeInformation.Unknown, LocalTypeInformation.Unknown)
|
Map::class.java.isAssignableFrom(type) -> LocalTypeInformation.AMap(type, typeIdentifier, LocalTypeInformation.Unknown, LocalTypeInformation.Unknown)
|
||||||
type.kotlin.javaPrimitiveType != null -> LocalTypeInformation.Atomic(type.kotlin.javaPrimitiveType!!, typeIdentifier)
|
type == String::class.java -> LocalTypeInformation.Atomic(String::class.java, typeIdentifier)
|
||||||
|
type.kotlin.javaPrimitiveType != null ->LocalTypeInformation.Atomic(type.kotlin.javaPrimitiveType!!, typeIdentifier)
|
||||||
type.isEnum -> LocalTypeInformation.AnEnum(
|
type.isEnum -> LocalTypeInformation.AnEnum(
|
||||||
type,
|
type,
|
||||||
typeIdentifier,
|
typeIdentifier,
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package net.corda.serialization.internal.amqp
|
package net.corda.serialization.internal.amqp
|
||||||
|
|
||||||
|
import net.corda.core.flows.FlowException
|
||||||
|
import net.corda.serialization.internal.amqp.custom.ThrowableSerializer
|
||||||
import net.corda.serialization.internal.amqp.testutils.serializeAndReturnSchema
|
import net.corda.serialization.internal.amqp.testutils.serializeAndReturnSchema
|
||||||
import net.corda.serialization.internal.amqp.testutils.testDefaultFactory
|
import net.corda.serialization.internal.amqp.testutils.testDefaultFactory
|
||||||
import net.corda.serialization.internal.model.*
|
import net.corda.serialization.internal.model.*
|
||||||
@ -43,10 +45,10 @@ class AMQPRemoteTypeModelTests {
|
|||||||
@Test
|
@Test
|
||||||
fun `round-trip some types through AMQP serialisations`() {
|
fun `round-trip some types through AMQP serialisations`() {
|
||||||
arrayOf("").assertRemoteType("String[]")
|
arrayOf("").assertRemoteType("String[]")
|
||||||
listOf(1).assertRemoteType("List<?>")
|
listOf(1).assertRemoteType("List<*>")
|
||||||
arrayOf(listOf(1)).assertRemoteType("List[]")
|
arrayOf(listOf(1)).assertRemoteType("List[]")
|
||||||
Enum.BAZ.assertRemoteType("Enum(FOO|BAR|BAZ)")
|
Enum.BAZ.assertRemoteType("Enum(FOO|BAR|BAZ)")
|
||||||
mapOf("string" to 1).assertRemoteType("Map<?, ?>")
|
mapOf("string" to 1).assertRemoteType("Map<*, *>")
|
||||||
arrayOf(byteArrayOf(1, 2, 3)).assertRemoteType("byte[][]")
|
arrayOf(byteArrayOf(1, 2, 3)).assertRemoteType("byte[][]")
|
||||||
|
|
||||||
SimpleClass(1, 2.0, null, byteArrayOf(1, 2, 3), byteArrayOf(4, 5, 6))
|
SimpleClass(1, 2.0, null, byteArrayOf(1, 2, 3), byteArrayOf(4, 5, 6))
|
||||||
@ -61,17 +63,18 @@ class AMQPRemoteTypeModelTests {
|
|||||||
|
|
||||||
C(arrayOf("a", "b"), listOf(UUID.randomUUID()), mapOf(UUID.randomUUID() to intArrayOf(1, 2, 3)), Enum.BAZ)
|
C(arrayOf("a", "b"), listOf(UUID.randomUUID()), mapOf(UUID.randomUUID() to intArrayOf(1, 2, 3)), Enum.BAZ)
|
||||||
.assertRemoteType("""
|
.assertRemoteType("""
|
||||||
C: Interface<String, UUID, ?>
|
C: Interface<String, UUID, *>
|
||||||
array: String[]
|
array: String[]
|
||||||
enum: Enum(FOO|BAR|BAZ)
|
enum: Enum(FOO|BAR|BAZ)
|
||||||
list: List<UUID>
|
list: List<UUID>
|
||||||
map: Map<UUID, ?>
|
map: Map<UUID, *>
|
||||||
""")
|
""")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getRemoteType(obj: Any): RemoteTypeInformation {
|
private fun getRemoteType(obj: Any): RemoteTypeInformation {
|
||||||
val output = SerializationOutput(factory)
|
val output = SerializationOutput(factory)
|
||||||
val schema = output.serializeAndReturnSchema(obj)
|
val schema = output.serializeAndReturnSchema(obj)
|
||||||
|
schema.schema.types.forEach { println(it) }
|
||||||
val values = typeModel.interpret(SerializationSchemas(schema.schema, schema.transformsSchema)).values
|
val values = typeModel.interpret(SerializationSchemas(schema.schema, schema.transformsSchema)).values
|
||||||
return values.find { it.typeIdentifier.getLocalType().asClass().isAssignableFrom(obj::class.java) } ?:
|
return values.find { it.typeIdentifier.getLocalType().asClass().isAssignableFrom(obj::class.java) } ?:
|
||||||
throw IllegalArgumentException(
|
throw IllegalArgumentException(
|
||||||
|
@ -67,7 +67,7 @@ class AMQPTypeIdentifierParserTests {
|
|||||||
assertParsesCompatibly<IntArray>()
|
assertParsesCompatibly<IntArray>()
|
||||||
assertParsesCompatibly<Array<Int>>()
|
assertParsesCompatibly<Array<Int>>()
|
||||||
assertParsesCompatibly<List<Int>>()
|
assertParsesCompatibly<List<Int>>()
|
||||||
assertParsesTo<WithParameter<*>>("WithParameter<?>")
|
assertParsesCompatibly<WithParameter<*>>()
|
||||||
assertParsesCompatibly<WithParameter<Int>>()
|
assertParsesCompatibly<WithParameter<Int>>()
|
||||||
assertParsesCompatibly<Array<out WithParameter<Int>>>()
|
assertParsesCompatibly<Array<out WithParameter<Int>>>()
|
||||||
assertParsesCompatibly<WithParameters<IntArray, WithParameter<Array<WithParameters<Array<Array<Date>>, UUID>>>>>()
|
assertParsesCompatibly<WithParameters<IntArray, WithParameter<Array<WithParameters<Array<Array<Date>>, UUID>>>>>()
|
||||||
|
Loading…
Reference in New Issue
Block a user