Updated to fix Jackson tests

This commit is contained in:
Chris Cochrane 2023-04-19 13:06:35 +01:00
parent 29dfda3730
commit c263ba7563
No known key found for this signature in database
GPG Key ID: 4D4602B5BBC63950
4 changed files with 16 additions and 2 deletions

View File

@ -63,7 +63,7 @@ buildscript {
ext.asm_version = '7.1'
ext.artemis_version = '2.6.2'
// TODO Upgrade to Jackson 2.10+ only when corda is using kotlin 1.3.10
ext.jackson_version = '2.13.3'
ext.jackson_version = '2.13.5'
ext.jackson_kotlin_version = '2.9.7'
ext.jetty_version = '9.4.19.v20190610'
ext.jersey_version = '2.25'

View File

@ -9,7 +9,9 @@ dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
// Jackson and its plugins: parsing to/from JSON and other textual formats.
compile "com.fasterxml.jackson.module:jackson-module-kotlin:$jackson_kotlin_version"
compile("com.fasterxml.jackson.module:jackson-module-kotlin:$jackson_kotlin_version") {
exclude module: "jackson-databind"
}
// Yaml is useful for parsing strings to method calls.
compile "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:$jackson_version"
// This adds support for java.time types.

View File

@ -6,6 +6,7 @@ import com.fasterxml.jackson.core.*
import com.fasterxml.jackson.databind.*
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
@ -179,6 +180,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))
}
}

View File

@ -19,6 +19,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
@ -114,6 +115,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() {