From 1e227fdfc458540672993130625cb51ec1f95e70 Mon Sep 17 00:00:00 2001 From: Rick Parker Date: Mon, 7 Mar 2022 11:08:06 +0000 Subject: [PATCH] ENT-6711 - Fix for upgrade to Jackson 2.12 and beyond (actual upgrade to 2.13.1) (#7096) * NOTICK - Don't know what the JIRA is but wanted to share. * Updates to resolve bukld issues * NOTICK: Fixed JDK11 version to prevent capsule version error * ENT-6711: Added comment for use of jackson_kotlin_version. * ENT-6711: Avoid deprecation warning, switched to the default method. Co-authored-by: Chris Cochrane Co-authored-by: Adel El-Beik --- .ci/dev/compatibility/DockerfileJDK11 | 2 +- build.gradle | 2 +- .../corda/client/jackson/JacksonSupport.kt | 38 ++++++++++-- .../client/jackson/internal/CordaModule.kt | 58 +++++++++++++++++-- .../node/services/rpc/CheckpointDumperImpl.kt | 2 +- samples/irs-demo/build.gradle | 3 +- 6 files changed, 90 insertions(+), 15 deletions(-) diff --git a/.ci/dev/compatibility/DockerfileJDK11 b/.ci/dev/compatibility/DockerfileJDK11 index 263c42a391..ff6eeaac95 100644 --- a/.ci/dev/compatibility/DockerfileJDK11 +++ b/.ci/dev/compatibility/DockerfileJDK11 @@ -1,4 +1,4 @@ -FROM azul/zulu-openjdk:11 +FROM azul/zulu-openjdk:11.0.14 RUN apt-get update && apt-get install -y curl apt-transport-https \ ca-certificates \ curl \ diff --git a/build.gradle b/build.gradle index a70e192e53..0407a5c69b 100644 --- a/build.gradle +++ b/build.gradle @@ -63,7 +63,7 @@ buildscript { ext.asm_version = '7.1' ext.artemis_version = '2.19.1' // TODO Upgrade Jackson only when corda is using kotlin 1.3.10 - ext.jackson_version = '2.11.1' + ext.jackson_version = '2.13.1' ext.jackson_kotlin_version = '2.9.7' ext.jetty_version = '9.4.19.v20190610' ext.jersey_version = '2.25' diff --git a/client/jackson/src/main/kotlin/net/corda/client/jackson/JacksonSupport.kt b/client/jackson/src/main/kotlin/net/corda/client/jackson/JacksonSupport.kt index 95f6f3e03c..46d7c105f3 100644 --- a/client/jackson/src/main/kotlin/net/corda/client/jackson/JacksonSupport.kt +++ b/client/jackson/src/main/kotlin/net/corda/client/jackson/JacksonSupport.kt @@ -2,10 +2,24 @@ package net.corda.client.jackson import com.fasterxml.jackson.annotation.JsonIgnore import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.core.* -import com.fasterxml.jackson.databind.* +import com.fasterxml.jackson.core.JsonFactory +import com.fasterxml.jackson.core.JsonGenerator +import com.fasterxml.jackson.core.JsonParseException +import com.fasterxml.jackson.core.JsonParser +import com.fasterxml.jackson.core.JsonToken +import com.fasterxml.jackson.databind.BeanDescription +import com.fasterxml.jackson.databind.DeserializationConfig +import com.fasterxml.jackson.databind.DeserializationContext +import com.fasterxml.jackson.databind.DeserializationFeature +import com.fasterxml.jackson.databind.JsonDeserializer +import com.fasterxml.jackson.databind.JsonSerializer +import com.fasterxml.jackson.databind.Module +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.databind.SerializationFeature +import com.fasterxml.jackson.databind.SerializerProvider import com.fasterxml.jackson.databind.annotation.JsonDeserialize import com.fasterxml.jackson.databind.annotation.JsonSerialize +import com.fasterxml.jackson.databind.cfg.ConstructorDetector import com.fasterxml.jackson.databind.deser.BeanDeserializerModifier import com.fasterxml.jackson.databind.deser.std.NumberDeserializers import com.fasterxml.jackson.databind.node.ObjectNode @@ -21,9 +35,21 @@ import net.corda.core.DoNotImplement import net.corda.core.contracts.Amount import net.corda.core.contracts.ContractState import net.corda.core.contracts.StateRef -import net.corda.core.crypto.* -import net.corda.core.identity.* -import net.corda.core.internal.* +import net.corda.core.crypto.Base58 +import net.corda.core.crypto.MerkleTree +import net.corda.core.crypto.SecureHash +import net.corda.core.crypto.TransactionSignature +import net.corda.core.crypto.toStringShort +import net.corda.core.identity.AbstractParty +import net.corda.core.identity.AnonymousParty +import net.corda.core.identity.CordaX500Name +import net.corda.core.identity.Party +import net.corda.core.identity.PartyAndCertificate +import net.corda.core.internal.CertRole +import net.corda.core.internal.VisibleForTesting +import net.corda.core.internal.isStatic +import net.corda.core.internal.kotlinObjectInstance +import net.corda.core.internal.uncheckedCast import net.corda.core.messaging.CordaRPCOps import net.corda.core.node.NodeInfo import net.corda.core.node.services.IdentityService @@ -179,6 +205,8 @@ object JacksonSupport { addMixIn(X500Principal::class.java, X500PrincipalMixin::class.java) addMixIn(X509Certificate::class.java, X509CertificateMixin::class.java) addMixIn(CertPath::class.java, CertPathMixin::class.java) + + setConstructorDetector(ConstructorDetector.DEFAULT.withAllowJDKTypeConstructors(true)) } } diff --git a/client/jackson/src/main/kotlin/net/corda/client/jackson/internal/CordaModule.kt b/client/jackson/src/main/kotlin/net/corda/client/jackson/internal/CordaModule.kt index 17e98ffd22..24e3efd707 100644 --- a/client/jackson/src/main/kotlin/net/corda/client/jackson/internal/CordaModule.kt +++ b/client/jackson/src/main/kotlin/net/corda/client/jackson/internal/CordaModule.kt @@ -2,16 +2,30 @@ package net.corda.client.jackson.internal -import com.fasterxml.jackson.annotation.* import com.fasterxml.jackson.annotation.JsonAutoDetect.Value import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonCreator.Mode.DISABLED +import com.fasterxml.jackson.annotation.JsonInclude import com.fasterxml.jackson.annotation.JsonInclude.Include +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.annotation.JsonTypeInfo +import com.fasterxml.jackson.annotation.JsonValue import com.fasterxml.jackson.core.JsonGenerator import com.fasterxml.jackson.core.JsonParseException import com.fasterxml.jackson.core.JsonParser import com.fasterxml.jackson.core.JsonToken -import com.fasterxml.jackson.databind.* +import com.fasterxml.jackson.databind.BeanDescription +import com.fasterxml.jackson.databind.BeanProperty +import com.fasterxml.jackson.databind.DeserializationConfig +import com.fasterxml.jackson.databind.DeserializationContext +import com.fasterxml.jackson.databind.JavaType +import com.fasterxml.jackson.databind.JsonDeserializer +import com.fasterxml.jackson.databind.JsonSerializer +import com.fasterxml.jackson.databind.Module +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.databind.SerializationConfig +import com.fasterxml.jackson.databind.SerializerProvider import com.fasterxml.jackson.databind.annotation.JsonDeserialize import com.fasterxml.jackson.databind.annotation.JsonSerialize import com.fasterxml.jackson.databind.cfg.MapperConfig @@ -19,6 +33,7 @@ import com.fasterxml.jackson.databind.deser.BeanDeserializerModifier import com.fasterxml.jackson.databind.deser.ContextualDeserializer import com.fasterxml.jackson.databind.deser.std.DelegatingDeserializer import com.fasterxml.jackson.databind.deser.std.FromStringDeserializer +import com.fasterxml.jackson.databind.introspect.AccessorNamingStrategy import com.fasterxml.jackson.databind.introspect.AnnotatedClass import com.fasterxml.jackson.databind.introspect.BasicClassIntrospector import com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector @@ -31,12 +46,30 @@ import com.fasterxml.jackson.databind.ser.std.StdScalarSerializer import com.fasterxml.jackson.databind.ser.std.UUIDSerializer import com.google.common.primitives.Booleans import net.corda.client.jackson.JacksonSupport -import net.corda.core.contracts.* -import net.corda.core.crypto.* +import net.corda.core.contracts.Amount +import net.corda.core.contracts.AttachmentConstraint +import net.corda.core.contracts.Command +import net.corda.core.contracts.CommandData +import net.corda.core.contracts.ContractState +import net.corda.core.contracts.PrivacySalt +import net.corda.core.contracts.StateRef +import net.corda.core.contracts.TimeWindow +import net.corda.core.contracts.TransactionState +import net.corda.core.crypto.Crypto +import net.corda.core.crypto.DigestService +import net.corda.core.crypto.DigitalSignature import net.corda.core.crypto.PartialMerkleTree.PartialTree +import net.corda.core.crypto.SecureHash import net.corda.core.crypto.SecureHash.Companion.SHA2_256 +import net.corda.core.crypto.SignatureMetadata +import net.corda.core.crypto.SignatureScheme +import net.corda.core.crypto.TransactionSignature import net.corda.core.flows.StateMachineRunId -import net.corda.core.identity.* +import net.corda.core.identity.AbstractParty +import net.corda.core.identity.AnonymousParty +import net.corda.core.identity.CordaX500Name +import net.corda.core.identity.Party +import net.corda.core.identity.PartyAndCertificate import net.corda.core.internal.DigitalSignatureWithCert import net.corda.core.internal.createComponentGroups import net.corda.core.node.NodeInfo @@ -44,7 +77,12 @@ import net.corda.core.serialization.SerializeAsToken import net.corda.core.serialization.SerializedBytes import net.corda.core.serialization.deserialize import net.corda.core.serialization.serialize -import net.corda.core.transactions.* +import net.corda.core.transactions.ContractUpgradeFilteredTransaction +import net.corda.core.transactions.ContractUpgradeWireTransaction +import net.corda.core.transactions.FilteredTransaction +import net.corda.core.transactions.NotaryChangeWireTransaction +import net.corda.core.transactions.SignedTransaction +import net.corda.core.transactions.WireTransaction import net.corda.core.utilities.ByteSequence import net.corda.core.utilities.NetworkHostAndPort import net.corda.core.utilities.parseAsHex @@ -117,6 +155,14 @@ private class CordaSerializableClassIntrospector(private val context: Module.Set } return super.constructPropertyCollector(config, ac, type, forSerialization, mutatorPrefix) } + + override fun constructPropertyCollector(config: MapperConfig<*>?, classDef: AnnotatedClass?, type: JavaType, forSerialization: Boolean, accNaming: AccessorNamingStrategy?): POJOPropertiesCollector { + if (hasCordaSerializable(type.rawClass)) { + // Adjust the field visibility of CordaSerializable classes on the fly as they are encountered. + context.configOverride(type.rawClass).visibility = Value.defaultVisibility().withFieldVisibility(Visibility.ANY) + } + return super.constructPropertyCollector(config, classDef, type, forSerialization, accNaming) + } } private class CordaSerializableBeanSerializerModifier : BeanSerializerModifier() { diff --git a/node/src/main/kotlin/net/corda/node/services/rpc/CheckpointDumperImpl.kt b/node/src/main/kotlin/net/corda/node/services/rpc/CheckpointDumperImpl.kt index 4e2e2a3153..a9aceab60b 100644 --- a/node/src/main/kotlin/net/corda/node/services/rpc/CheckpointDumperImpl.kt +++ b/node/src/main/kotlin/net/corda/node/services/rpc/CheckpointDumperImpl.kt @@ -584,7 +584,7 @@ class CheckpointDumperImpl(private val checkpointStorage: CheckpointStorage, pri private object MapSerializer : JsonSerializer>() { override fun serialize(map: Map, gen: JsonGenerator, serializers: SerializerProvider) { - gen.writeStartArray(map.size) + gen.writeStartArray() map.forEach { (key, value) -> gen.jsonObject { writeObjectField("key", key) diff --git a/samples/irs-demo/build.gradle b/samples/irs-demo/build.gradle index 700dd73dc4..0cf5896f9a 100644 --- a/samples/irs-demo/build.gradle +++ b/samples/irs-demo/build.gradle @@ -9,7 +9,8 @@ plugins { ext['artemis.version'] = "$artemis_version" ext['hibernate.version'] = "$hibernate_version" ext['selenium.version'] = "$selenium_version" -ext['jackson.version'] = "$jackson_version" +// Using jackson_kotlin_version here for JDK11 compatibility with kotlin 1.2.71 +ext['jackson.version'] = "$jackson_kotlin_version" ext['dropwizard-metrics.version'] = "$metrics_version" ext['mockito.version'] = "$mockito_version"