diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/KotlinInstantiatorsTest.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/KotlinInstantiatorsTest.kt index 628f5afc8..50286ba76 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/KotlinInstantiatorsTest.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/KotlinInstantiatorsTest.kt @@ -5,8 +5,7 @@ import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.Test class KotlinInstantiatorsTest { - private val mapper = jacksonObjectMapper() - private val deserConfig = mapper.deserializationConfig + private val deserConfig = defaultMapper.deserializationConfig private val kotlinInstantiators = KotlinInstantiators( ReflectionCache(10), @@ -18,7 +17,7 @@ class KotlinInstantiatorsTest { @Test fun `Provides default instantiator for Java class`() { - val javaType = mapper.constructType(String::class.java) + val javaType = defaultMapper.constructType(String::class.java) val defaultInstantiator = StdValueInstantiator(deserConfig, javaType) val instantiator = kotlinInstantiators.findValueInstantiator( deserConfig, @@ -33,7 +32,7 @@ class KotlinInstantiatorsTest { fun `Provides KotlinValueInstantiator for Kotlin class`() { class TestClass - val javaType = mapper.constructType(TestClass::class.java) + val javaType = defaultMapper.constructType(TestClass::class.java) val instantiator = kotlinInstantiators.findValueInstantiator( deserConfig, deserConfig.introspect(javaType), @@ -51,15 +50,15 @@ class KotlinInstantiatorsTest { val subClassInstantiator = object : StdValueInstantiator( deserConfig, - mapper.constructType(DefaultClass::class.java) + defaultMapper.constructType(DefaultClass::class.java) ) {} assertThrows(IllegalStateException::class.java) { kotlinInstantiators.findValueInstantiator( deserConfig, - deserConfig.introspect(mapper.constructType(TestClass::class.java)), + deserConfig.introspect(defaultMapper.constructType(TestClass::class.java)), subClassInstantiator ) } } -} \ No newline at end of file +} diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/NullableObjectEdgeCases.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/NullableObjectEdgeCases.kt index 26f2eabba..a8027784d 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/NullableObjectEdgeCases.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/NullableObjectEdgeCases.kt @@ -7,7 +7,7 @@ import com.fasterxml.jackson.databind.DeserializationContext import com.fasterxml.jackson.databind.annotation.JsonDeserialize import com.fasterxml.jackson.databind.deser.std.StdDeserializer import com.fasterxml.jackson.module.kotlin.WrapsNullableValueClassDeserializer -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.readValue import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test @@ -38,7 +38,7 @@ class NullableObjectEdgeCases { @Test fun nullValueIsUsedPreferentially() { - val result = jacksonObjectMapper().readValue("""{"nn":null,"n":null}""") + val result = defaultMapper.readValue("""{"nn":null,"n":null}""") assertEquals(NullValue(NullValueDeserializer.nv, NullValueDeserializer.nv), result) } @@ -62,7 +62,7 @@ class NullableObjectEdgeCases { @Test fun `Nulls_SKIP works`() { assertThrows("#761(KT-57357) fixed") { - val result = jacksonObjectMapper().readValue("""{"nn":null,"n":null}""") + val result = defaultMapper.readValue("""{"nn":null,"n":null}""") assertEquals(NullValue(VC("skip"), VC("skip")), result) } } diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/WithoutCustomDeserializeMethodTest.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/WithoutCustomDeserializeMethodTest.kt index 760efb7de..7706f66c2 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/WithoutCustomDeserializeMethodTest.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/WithoutCustomDeserializeMethodTest.kt @@ -1,7 +1,6 @@ package com.fasterxml.jackson.module.kotlin.kogeraIntegration.deser.valueClass import com.fasterxml.jackson.module.kotlin.defaultMapper -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper import com.fasterxml.jackson.module.kotlin.readValue import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertTrue @@ -13,7 +12,6 @@ import kotlin.test.assertNotEquals class WithoutCustomDeserializeMethodTest { companion object { - val mapper = jacksonObjectMapper() val throwable = IllegalArgumentException("test") } @@ -68,8 +66,8 @@ class WithoutCustomDeserializeMethodTest { NullableObject("baz"), NullableObject("qux") ) - val src = mapper.writeValueAsString(expected) - val result = mapper.readValue(src) + val src = defaultMapper.writeValueAsString(expected) + val result = defaultMapper.readValue(src) assertEquals(expected, result) } @@ -84,8 +82,8 @@ class WithoutCustomDeserializeMethodTest { NullableObject(null), null ) - val src = mapper.writeValueAsString(expected) - val result = mapper.readValue(src) + val src = defaultMapper.writeValueAsString(expected) + val result = defaultMapper.readValue(src) assertEquals(expected, result) } diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/defaultArgument/NonNullObjectTest.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/defaultArgument/NonNullObjectTest.kt index 4d12664c7..c4bd38e53 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/defaultArgument/NonNullObjectTest.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/defaultArgument/NonNullObjectTest.kt @@ -1,17 +1,13 @@ package com.fasterxml.jackson.module.kotlin.kogeraIntegration.deser.valueClass.defaultArgument import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.kogeraIntegration.deser.valueClass.NonNullObject import com.fasterxml.jackson.module.kotlin.readValue import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test class NonNullObjectTest { - companion object { - val mapper = jacksonObjectMapper() - } - data class ByConstructor( val nn: NonNullObject = NonNullObject("foo"), val nNn: NonNullObject? = NonNullObject("bar"), @@ -20,7 +16,7 @@ class NonNullObjectTest { @Test fun byConstructorTest() { - assertEquals(ByConstructor(), mapper.readValue("{}")) + assertEquals(ByConstructor(), defaultMapper.readValue("{}")) } data class ByFactory(val nn: NonNullObject, val nNn: NonNullObject?, val nN: NonNullObject?) { @@ -37,6 +33,6 @@ class NonNullObjectTest { @Test fun byFactoryTest() { - assertEquals(ByFactory.creator(), mapper.readValue("{}")) + assertEquals(ByFactory.creator(), defaultMapper.readValue("{}")) } } diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/defaultArgument/NullableObjectTest.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/defaultArgument/NullableObjectTest.kt index d94b316c7..09dc3ee85 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/defaultArgument/NullableObjectTest.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/defaultArgument/NullableObjectTest.kt @@ -1,7 +1,7 @@ package com.fasterxml.jackson.module.kotlin.kogeraIntegration.deser.valueClass.defaultArgument import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.kogeraIntegration.deser.valueClass.NullableObject import com.fasterxml.jackson.module.kotlin.readValue import org.junit.jupiter.api.Assertions.assertEquals @@ -9,10 +9,6 @@ import org.junit.jupiter.api.Assertions.assertThrows import org.junit.jupiter.api.Test class NullableObjectTest { - companion object { - val mapper = jacksonObjectMapper() - } - data class ByConstructor( val nnNn: NullableObject = NullableObject("foo"), val nnN: NullableObject = NullableObject(null), @@ -24,7 +20,7 @@ class NullableObjectTest { fun byConstructorTestFailing() { // #761(KT-57357) fixed assertThrows(Error::class.java) { - assertEquals(ByConstructor(), mapper.readValue("{}")) + assertEquals(ByConstructor(), defaultMapper.readValue("{}")) } } @@ -50,7 +46,7 @@ class NullableObjectTest { fun byFactoryTest() { // #761(KT-57357) fixed assertThrows(Error::class.java) { - assertEquals(ByFactory.creator(), mapper.readValue("{}")) + assertEquals(ByFactory.creator(), defaultMapper.readValue("{}")) } } } diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/defaultArgument/PrimitiveTest.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/defaultArgument/PrimitiveTest.kt index a79794605..062df6f7b 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/defaultArgument/PrimitiveTest.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/defaultArgument/PrimitiveTest.kt @@ -1,17 +1,13 @@ package com.fasterxml.jackson.module.kotlin.kogeraIntegration.deser.valueClass.defaultArgument import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.kogeraIntegration.deser.valueClass.Primitive import com.fasterxml.jackson.module.kotlin.readValue import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test class PrimitiveTest { - companion object { - val mapper = jacksonObjectMapper() - } - data class ByConstructor( val nn: Primitive = Primitive(1), val nNn: Primitive? = Primitive(2), @@ -20,7 +16,7 @@ class PrimitiveTest { @Test fun byConstructorTest() { - assertEquals(ByConstructor(), mapper.readValue("{}")) + assertEquals(ByConstructor(), defaultMapper.readValue("{}")) } data class ByFactory(val nn: Primitive, val nNn: Primitive?, val nN: Primitive?) { @@ -37,6 +33,6 @@ class PrimitiveTest { @Test fun byFactoryTest() { - assertEquals(ByFactory.creator(), mapper.readValue("{}")) + assertEquals(ByFactory.creator(), defaultMapper.readValue("{}")) } } diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/deserializer/byAnnotation/SpecifiedForClassTest.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/deserializer/byAnnotation/SpecifiedForClassTest.kt index 8b8bcb19f..d0feed052 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/deserializer/byAnnotation/SpecifiedForClassTest.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/deserializer/byAnnotation/SpecifiedForClassTest.kt @@ -4,7 +4,7 @@ import com.fasterxml.jackson.core.JsonParser import com.fasterxml.jackson.databind.DeserializationContext import com.fasterxml.jackson.databind.annotation.JsonDeserialize import com.fasterxml.jackson.databind.deser.std.StdDeserializer -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.readValue import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test @@ -20,8 +20,7 @@ class SpecifiedForClassTest { @Test fun directDeserTest() { - val mapper = jacksonObjectMapper() - val result = mapper.readValue("1") + val result = defaultMapper.readValue("1") assertEquals(Value(101), result) } @@ -30,8 +29,7 @@ class SpecifiedForClassTest { @Test fun paramDeserTest() { - val mapper = jacksonObjectMapper() - val result = mapper.readValue("""{"v":1}""") + val result = defaultMapper.readValue("""{"v":1}""") assertEquals(Wrapper(Value(101)), result) } diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/deserializer/byAnnotation/specifiedForProperty/NonNullObjectTest.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/deserializer/byAnnotation/specifiedForProperty/NonNullObjectTest.kt index 240722276..99a5378fd 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/deserializer/byAnnotation/specifiedForProperty/NonNullObjectTest.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/deserializer/byAnnotation/specifiedForProperty/NonNullObjectTest.kt @@ -1,7 +1,7 @@ package com.fasterxml.jackson.module.kotlin.kogeraIntegration.deser.valueClass.deserializer.byAnnotation.specifiedForProperty import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.kogeraIntegration.deser.valueClass.NonNullObject import com.fasterxml.jackson.module.kotlin.readValue import org.junit.jupiter.api.Assertions.assertEquals @@ -9,10 +9,6 @@ import org.junit.jupiter.api.Nested import org.junit.jupiter.api.Test class NonNullObjectTest { - companion object { - val mapper = jacksonObjectMapper() - } - data class NonNull( @get:JsonDeserialize(using = NonNullObject.Deserializer::class) val getterAnn: NonNullObject, @@ -22,7 +18,7 @@ class NonNullObjectTest { @Test fun nonNull() { - val result = mapper.readValue( + val result = defaultMapper.readValue( """ { "getterAnn" : "foo", @@ -44,7 +40,7 @@ class NonNullObjectTest { inner class NullableTest { @Test fun nonNullInput() { - val result = mapper.readValue( + val result = defaultMapper.readValue( """ { "getterAnn" : "foo", @@ -57,7 +53,7 @@ class NonNullObjectTest { @Test fun nullInput() { - val result = mapper.readValue( + val result = defaultMapper.readValue( """ { "getterAnn" : null, diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/deserializer/byAnnotation/specifiedForProperty/NullableObjectTest.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/deserializer/byAnnotation/specifiedForProperty/NullableObjectTest.kt index a7413fcb2..42c16df07 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/deserializer/byAnnotation/specifiedForProperty/NullableObjectTest.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/deserializer/byAnnotation/specifiedForProperty/NullableObjectTest.kt @@ -1,7 +1,7 @@ package com.fasterxml.jackson.module.kotlin.kogeraIntegration.deser.valueClass.deserializer.byAnnotation.specifiedForProperty import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.kogeraIntegration.deser.valueClass.NullableObject import com.fasterxml.jackson.module.kotlin.readValue import org.junit.jupiter.api.Assertions.assertEquals @@ -9,10 +9,6 @@ import org.junit.jupiter.api.Nested import org.junit.jupiter.api.Test class NullableObjectTest { - companion object { - val mapper = jacksonObjectMapper() - } - data class NonNull( @get:JsonDeserialize(using = NullableObject.DeserializerWrapsNullable::class) val getterAnn: NullableObject, @@ -22,7 +18,7 @@ class NullableObjectTest { @Test fun nonNull() { - val result = mapper.readValue( + val result = defaultMapper.readValue( """ { "getterAnn" : "foo", @@ -44,7 +40,7 @@ class NullableObjectTest { inner class NullableTest { @Test fun nonNullInput() { - val result = mapper.readValue( + val result = defaultMapper.readValue( """ { "getterAnn" : "foo", @@ -57,7 +53,7 @@ class NullableObjectTest { @Test fun nullInput() { - val result = mapper.readValue( + val result = defaultMapper.readValue( """ { "getterAnn" : null, diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/deserializer/byAnnotation/specifiedForProperty/PrimitiveTest.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/deserializer/byAnnotation/specifiedForProperty/PrimitiveTest.kt index 8945587e7..831b82973 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/deserializer/byAnnotation/specifiedForProperty/PrimitiveTest.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/deserializer/byAnnotation/specifiedForProperty/PrimitiveTest.kt @@ -1,7 +1,7 @@ package com.fasterxml.jackson.module.kotlin.kogeraIntegration.deser.valueClass.deserializer.byAnnotation.specifiedForProperty import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.kogeraIntegration.deser.valueClass.Primitive import com.fasterxml.jackson.module.kotlin.readValue import org.junit.jupiter.api.Assertions.assertEquals @@ -9,10 +9,6 @@ import org.junit.jupiter.api.Nested import org.junit.jupiter.api.Test class PrimitiveTest { - companion object { - val mapper = jacksonObjectMapper() - } - data class NonNull( @get:JsonDeserialize(using = Primitive.Deserializer::class) val getterAnn: Primitive, @@ -22,7 +18,7 @@ class PrimitiveTest { @Test fun nonNull() { - val result = mapper.readValue( + val result = defaultMapper.readValue( """ { "getterAnn" : 1, @@ -44,7 +40,7 @@ class PrimitiveTest { inner class NullableTest { @Test fun nonNullInput() { - val result = mapper.readValue( + val result = defaultMapper.readValue( """ { "getterAnn" : 1, @@ -57,7 +53,7 @@ class PrimitiveTest { @Test fun nullInput() { - val result = mapper.readValue( + val result = defaultMapper.readValue( """ { "getterAnn" : null, diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/jsonCreator/HandledByJacksonTest.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/jsonCreator/HandledByJacksonTest.kt index effeea18f..455f5f67a 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/jsonCreator/HandledByJacksonTest.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/jsonCreator/HandledByJacksonTest.kt @@ -1,7 +1,7 @@ package com.fasterxml.jackson.module.kotlin.kogeraIntegration.deser.valueClass.jsonCreator import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.readValue import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test @@ -21,8 +21,7 @@ class HandledByJacksonTest { @Test fun primitiveNullableCreatorTest() { - val mapper = jacksonObjectMapper() - val r: PrimitiveMultiParamCreator = mapper.readValue("""{"first":1,"second":2}""") + val r: PrimitiveMultiParamCreator = defaultMapper.readValue("""{"first":1,"second":2}""") assertEquals(PrimitiveMultiParamCreator(3), r) } @@ -39,8 +38,7 @@ class HandledByJacksonTest { @Test fun nullableObjectNullableCreatorTest() { - val mapper = jacksonObjectMapper() - val r: NullableObjectMultiParamCreator = mapper.readValue("""{"first":1,"second":2}""") + val r: NullableObjectMultiParamCreator = defaultMapper.readValue("""{"first":1,"second":2}""") assertEquals(NullableObjectMultiParamCreator(3), r) } } diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/jsonCreator/HandledByKogeraTest.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/jsonCreator/HandledByKogeraTest.kt index bf76a9c2f..eab4d2b77 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/jsonCreator/HandledByKogeraTest.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/jsonCreator/HandledByKogeraTest.kt @@ -2,7 +2,7 @@ package com.fasterxml.jackson.module.kotlin.kogeraIntegration.deser.valueClass.j import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.databind.exc.InvalidDefinitionException -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.readValue import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertThrows @@ -29,11 +29,9 @@ class HandledByKogeraTest { @Test fun directDeserTest() { - val mapper = jacksonObjectMapper() - - assertEquals(SpecifiedPrimary("b"), mapper.readValue("\"b\"")) - assertEquals(Secondary("1-creator"), mapper.readValue("1")) - assertEquals(Factory(101), mapper.readValue("1")) + assertEquals(SpecifiedPrimary("b"), defaultMapper.readValue("\"b\"")) + assertEquals(Secondary("1-creator"), defaultMapper.readValue("1")) + assertEquals(Factory(101), defaultMapper.readValue("1")) } data class Dst( @@ -44,9 +42,7 @@ class HandledByKogeraTest { @Test fun parameterTest() { - val mapper = jacksonObjectMapper() - - val r = mapper.readValue( + val r = defaultMapper.readValue( """ { "bar":"b", @@ -83,13 +79,11 @@ class HandledByKogeraTest { // A Creator that requires multiple arguments is basically an error. @Test fun handleErrorTest() { - val mapper = jacksonObjectMapper() - assertThrows(InvalidDefinitionException::class.java) { - mapper.readValue("""{"v1":"1","v2":"2"}""") + defaultMapper.readValue("""{"v1":"1","v2":"2"}""") } assertThrows(InvalidDefinitionException::class.java) { - mapper.readValue("""{"v1":1,"v2":2}""") + defaultMapper.readValue("""{"v1":1,"v2":2}""") } } } diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/jsonCreator/InCreatorArgumentTest.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/jsonCreator/InCreatorArgumentTest.kt index cd1961622..ddd9ecb7f 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/jsonCreator/InCreatorArgumentTest.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/jsonCreator/InCreatorArgumentTest.kt @@ -1,7 +1,7 @@ package com.fasterxml.jackson.module.kotlin.kogeraIntegration.deser.valueClass.jsonCreator import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.kogeraIntegration.deser.valueClass.NonNullObject import com.fasterxml.jackson.module.kotlin.kogeraIntegration.deser.valueClass.NullableObject import com.fasterxml.jackson.module.kotlin.kogeraIntegration.deser.valueClass.Primitive @@ -45,7 +45,6 @@ class InCreatorArgumentTest { @Test fun test() { - val mapper = jacksonObjectMapper() val base = Dst( Primitive(1), Primitive(2), @@ -54,7 +53,7 @@ class InCreatorArgumentTest { NullableObject("noNn"), NullableObject("noN") ) - val result = mapper.readValue(mapper.writeValueAsString(base)) + val result = defaultMapper.readValue(defaultMapper.writeValueAsString(base)) assertEquals( base.copy( diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/mapKey/keyDeserializer/byAnnotation/SpecifiedForClassTest.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/mapKey/keyDeserializer/byAnnotation/SpecifiedForClassTest.kt index 38642f058..2d363df57 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/mapKey/keyDeserializer/byAnnotation/SpecifiedForClassTest.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/mapKey/keyDeserializer/byAnnotation/SpecifiedForClassTest.kt @@ -3,7 +3,6 @@ package com.fasterxml.jackson.module.kotlin.kogeraIntegration.deser.valueClass.m import com.fasterxml.jackson.databind.DeserializationContext import com.fasterxml.jackson.databind.annotation.JsonDeserialize import com.fasterxml.jackson.module.kotlin.defaultMapper -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper import com.fasterxml.jackson.module.kotlin.readValue import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test @@ -29,8 +28,7 @@ class SpecifiedForClassTest { @Test fun paramDeserTest() { - val mapper = jacksonObjectMapper() - val result = mapper.readValue("""{"v":{"1":null}}""") + val result = defaultMapper.readValue("""{"v":{"1":null}}""") assertEquals(Wrapper(mapOf(Value(101) to null)), result) } diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/mapKey/keyDeserializer/byAnnotation/SpecifiedForPropertyTest.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/mapKey/keyDeserializer/byAnnotation/SpecifiedForPropertyTest.kt index 5dd383c26..49c8eb365 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/mapKey/keyDeserializer/byAnnotation/SpecifiedForPropertyTest.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/mapKey/keyDeserializer/byAnnotation/SpecifiedForPropertyTest.kt @@ -2,7 +2,7 @@ package com.fasterxml.jackson.module.kotlin.kogeraIntegration.deser.valueClass.m import com.fasterxml.jackson.databind.DeserializationContext import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.readValue import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test @@ -20,8 +20,7 @@ class SpecifiedForPropertyTest { @Test fun paramDeserTest() { - val mapper = jacksonObjectMapper() - val result = mapper.readValue("""{"v":{"1":null}}""") + val result = defaultMapper.readValue("""{"v":{"1":null}}""") assertEquals(Wrapper(mapOf(Value(101) to null)), result) } diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/ser.valueClass/jsonInclude/JsonIncludeCustomTest.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/ser.valueClass/jsonInclude/JsonIncludeCustomTest.kt index a162e482f..7f5a502a0 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/ser.valueClass/jsonInclude/JsonIncludeCustomTest.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/ser.valueClass/jsonInclude/JsonIncludeCustomTest.kt @@ -1,7 +1,7 @@ package com.fasterxml.jackson.module.kotlin.kogeraIntegration.ser.valueClass.jsonInclude import com.fasterxml.jackson.annotation.JsonInclude -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import kotlin.test.Test import kotlin.test.assertEquals @@ -22,8 +22,7 @@ class JsonIncludeCustomTest { @Test fun nullFilterTest() { - val mapper = jacksonObjectMapper() val dto = NullFilterDto() - assertEquals("{}", mapper.writeValueAsString(dto)) + assertEquals("{}", defaultMapper.writeValueAsString(dto)) } } diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/ser.valueClass/jsonInclude/JsonIncludeNonNullTest.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/ser.valueClass/jsonInclude/JsonIncludeNonNullTest.kt index 82de3fe62..ef8535d7e 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/ser.valueClass/jsonInclude/JsonIncludeNonNullTest.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/ser.valueClass/jsonInclude/JsonIncludeNonNullTest.kt @@ -1,7 +1,7 @@ package com.fasterxml.jackson.module.kotlin.kogeraIntegration.ser.valueClass.jsonInclude import com.fasterxml.jackson.annotation.JsonInclude -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertNotEquals @@ -16,9 +16,8 @@ class JsonIncludeNonNullTest { @Test fun success() { - val mapper = jacksonObjectMapper() val dto = Dto() - assertEquals("{}", mapper.writeValueAsString(dto)) + assertEquals("{}", defaultMapper.writeValueAsString(dto)) } // It is under consideration whether it should be serialized because it is non-null in Kotlin, @@ -32,9 +31,8 @@ class JsonIncludeNonNullTest { @Test fun fails() { - val mapper = jacksonObjectMapper() val dto = DtoFails() - val result = mapper.writeValueAsString(dto) + val result = defaultMapper.writeValueAsString(dto) assertNotEquals("""{"map":{}}""", result) assertEquals("""{"noNn":null,"noN2":null,"map":{"noNn":null}}""", result) } diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/SealedClassTest.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/SealedClassTest.kt index 7f482af6d..ea49ef757 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/SealedClassTest.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/SealedClassTest.kt @@ -5,15 +5,13 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo import com.fasterxml.jackson.annotation.JsonValue import com.fasterxml.jackson.core.type.TypeReference import com.fasterxml.jackson.databind.exc.MismatchedInputException -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.test.SealedClassTest.SuperClass.B import org.junit.jupiter.api.Test import kotlin.test.assertEquals import kotlin.test.assertTrue class SealedClassTest { - private val mapper = jacksonObjectMapper() - /** * Json of a Serialized B-Object. */ @@ -24,13 +22,13 @@ class SealedClassTest { */ @Test fun sealedClassWithoutSubTypes() { - val result = mapper.readValue(jsonB, SuperClass::class.java) + val result = defaultMapper.readValue(jsonB, SuperClass::class.java) assertTrue { result is B } } @Test fun sealedClassWithoutSubTypesList() { - val result = mapper.readValue( + val result = defaultMapper.readValue( """[$jsonB, $jsonB]""", object : TypeReference>() {} ) @@ -49,7 +47,7 @@ class SealedClassTest { @Test fun sealedClassWithoutTypeDiscriminator() { val serializedSingle = """{"request":"single"}""" - val single = mapper.readValue(serializedSingle, SealedRequest::class.java) + val single = defaultMapper.readValue(serializedSingle, SealedRequest::class.java) assertTrue(single is SealedRequest.SingleRequest) assertEquals("single", single.request) } @@ -61,7 +59,7 @@ class SealedClassTest { fun sealedClassWithoutTypeDiscriminatorList() { val serializedBatch = """[{"request":"first"},{"request":"second"}]""" expectFailure("Deserializing a list using deduction is fixed!") { - val batch = mapper.readValue(serializedBatch, SealedRequest::class.java) + val batch = defaultMapper.readValue(serializedBatch, SealedRequest::class.java) assertTrue(batch is SealedRequest.BatchRequest) assertEquals(2, batch.requests.size) assertEquals("first", batch.requests[0].request) diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/SequenceSerdesTests.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/SequenceSerdesTests.kt index d64016bdd..20024ab5a 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/SequenceSerdesTests.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/SequenceSerdesTests.kt @@ -4,7 +4,7 @@ import com.fasterxml.jackson.core.JsonGenerator import com.fasterxml.jackson.databind.SerializerProvider import com.fasterxml.jackson.databind.annotation.JsonSerialize import com.fasterxml.jackson.databind.ser.std.StdSerializer -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.readValue import org.junit.jupiter.api.Test import kotlin.test.assertEquals @@ -16,16 +16,14 @@ class TestSequenceDeserializer { @Test fun deserializeSequence() { val list = listOf("Test", "Test1") - val objectMapper = jacksonObjectMapper() - val result = objectMapper.readValue("{\"value\":[\"Test\",\"Test1\"]}") + val result = defaultMapper.readValue("{\"value\":[\"Test\",\"Test1\"]}") assertEquals(list, result.value.toList()) } @Test fun deserializeEmptySequence() { val list = listOf() - val objectMapper = jacksonObjectMapper() - val result = objectMapper.readValue("{\"value\":[]}") + val result = defaultMapper.readValue("{\"value\":[]}") assertEquals(list, result.value.toList()) } @@ -33,8 +31,7 @@ class TestSequenceDeserializer { fun testSerializeSequence() { val sequence = listOf("item1", "item2").asSequence() val data = Data(sequence) - val objectMapper = jacksonObjectMapper() - val result = objectMapper.writeValueAsString(data) + val result = defaultMapper.writeValueAsString(data) assertEquals("{\"value\":[\"item1\",\"item2\"]}", result) } @@ -42,8 +39,7 @@ class TestSequenceDeserializer { fun testSerializeEmptySequence() { val sequence = listOf().asSequence() val data = Data(sequence) - val objectMapper = jacksonObjectMapper() - val result = objectMapper.writeValueAsString(data) + val result = defaultMapper.writeValueAsString(data) assertEquals("{\"value\":[]}", result) } @@ -64,10 +60,8 @@ class TestSequenceDeserializer { @Test fun contentUsingTest() { - val mapper = jacksonObjectMapper() - - val listResult = mapper.writeValueAsString(ListWrapper(listOf("foo"))) - val sequenceResult = mapper.writeValueAsString(SequenceWrapper(sequenceOf("foo"))) + val listResult = defaultMapper.writeValueAsString(ListWrapper(listOf("foo"))) + val sequenceResult = defaultMapper.writeValueAsString(SequenceWrapper(sequenceOf("foo"))) assertEquals("""{"value":["foo-ser"]}""", sequenceResult) assertEquals(listResult, sequenceResult) @@ -76,8 +70,7 @@ class TestSequenceDeserializer { // @see #674 @Test fun sequenceOfTest() { - val mapper = jacksonObjectMapper() - val result = mapper.writeValueAsString(sequenceOf("foo")) + val result = defaultMapper.writeValueAsString(sequenceOf("foo")) assertEquals("""["foo"]""", result) } diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/UnsignedNumbersOnKeyTest.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/UnsignedNumbersOnKeyTest.kt index 082eff776..1ef1f5a9f 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/UnsignedNumbersOnKeyTest.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/UnsignedNumbersOnKeyTest.kt @@ -1,7 +1,7 @@ package com.fasterxml.jackson.module.kotlin.test import com.fasterxml.jackson.core.exc.InputCoercionException -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.readValue import org.junit.jupiter.api.Assertions.assertThrows import org.junit.jupiter.api.Nested @@ -10,106 +10,102 @@ import java.math.BigInteger import kotlin.test.assertEquals internal class UnsignedNumbersOnKeyTest { - companion object { - val MAPPER = jacksonObjectMapper() - } - @Nested inner class ForUByte { - private fun makeSrc(v: Int): String = MAPPER.writeValueAsString(mapOf(v to 0)) + private fun makeSrc(v: Int): String = defaultMapper.writeValueAsString(mapOf(v to 0)) @Test fun test() { - val actual = MAPPER.readValue>(makeSrc(UByte.MAX_VALUE.toInt())) + val actual = defaultMapper.readValue>(makeSrc(UByte.MAX_VALUE.toInt())) assertEquals(mapOf(UByte.MAX_VALUE to 0.toUByte()), actual) } @Test fun overflow() { assertThrows(InputCoercionException::class.java) { - MAPPER.readValue>(makeSrc(UByte.MAX_VALUE.toInt() + 1)) + defaultMapper.readValue>(makeSrc(UByte.MAX_VALUE.toInt() + 1)) } } @Test fun underflow() { assertThrows(InputCoercionException::class.java) { - MAPPER.readValue>(makeSrc(-1)) + defaultMapper.readValue>(makeSrc(-1)) } } } @Nested inner class ForUShort { - private fun makeSrc(v: Int): String = MAPPER.writeValueAsString(mapOf(v to 0)) + private fun makeSrc(v: Int): String = defaultMapper.writeValueAsString(mapOf(v to 0)) @Test fun test() { - val actual = MAPPER.readValue>(makeSrc(UShort.MAX_VALUE.toInt())) + val actual = defaultMapper.readValue>(makeSrc(UShort.MAX_VALUE.toInt())) assertEquals(mapOf(UShort.MAX_VALUE to 0.toUShort()), actual) } @Test fun overflow() { assertThrows(InputCoercionException::class.java) { - MAPPER.readValue>(makeSrc(UShort.MAX_VALUE.toInt() + 1)) + defaultMapper.readValue>(makeSrc(UShort.MAX_VALUE.toInt() + 1)) } } @Test fun underflow() { assertThrows(InputCoercionException::class.java) { - MAPPER.readValue>(makeSrc(-1)) + defaultMapper.readValue>(makeSrc(-1)) } } } @Nested inner class ForUInt { - private fun makeSrc(v: Long): String = MAPPER.writeValueAsString(mapOf(v to 0)) + private fun makeSrc(v: Long): String = defaultMapper.writeValueAsString(mapOf(v to 0)) @Test fun test() { - val actual = MAPPER.readValue>(makeSrc(UInt.MAX_VALUE.toLong())) + val actual = defaultMapper.readValue>(makeSrc(UInt.MAX_VALUE.toLong())) assertEquals(mapOf(UInt.MAX_VALUE to 0.toUInt()), actual) } @Test fun overflow() { assertThrows(InputCoercionException::class.java) { - MAPPER.readValue>(makeSrc(UInt.MAX_VALUE.toLong() + 1L)) + defaultMapper.readValue>(makeSrc(UInt.MAX_VALUE.toLong() + 1L)) } } @Test fun underflow() { assertThrows(InputCoercionException::class.java) { - MAPPER.readValue>(makeSrc(-1L)) + defaultMapper.readValue>(makeSrc(-1L)) } } } @Nested inner class ForULong { - private fun makeSrc(v: BigInteger): String = MAPPER.writeValueAsString(mapOf(v to 0)) + private fun makeSrc(v: BigInteger): String = defaultMapper.writeValueAsString(mapOf(v to 0)) @Test fun test() { - val actual = MAPPER.readValue>(makeSrc(BigInteger(ULong.MAX_VALUE.toString()))) + val actual = defaultMapper.readValue>(makeSrc(BigInteger(ULong.MAX_VALUE.toString()))) assertEquals(mapOf(ULong.MAX_VALUE to 0.toULong()), actual) } @Test fun overflow() { assertThrows(InputCoercionException::class.java) { - MAPPER.readValue>(makeSrc(BigInteger(ULong.MAX_VALUE.toString()) + BigInteger.ONE)) + defaultMapper.readValue>(makeSrc(BigInteger(ULong.MAX_VALUE.toString()) + BigInteger.ONE)) } } @Test fun underflow() { assertThrows(InputCoercionException::class.java) { - MAPPER.readValue>(makeSrc(BigInteger.valueOf(-1L))) + defaultMapper.readValue>(makeSrc(BigInteger.valueOf(-1L))) } } } diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/UnsignedNumbersTests.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/UnsignedNumbersTests.kt index 0f480d020..40d453b41 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/UnsignedNumbersTests.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/UnsignedNumbersTests.kt @@ -1,8 +1,7 @@ package com.fasterxml.jackson.module.kotlin.test import com.fasterxml.jackson.core.exc.InputCoercionException -import com.fasterxml.jackson.databind.ObjectMapper -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.readValue import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test @@ -11,82 +10,80 @@ import java.math.BigInteger internal class UnsignedNumbersTests { - val mapper: ObjectMapper = jacksonObjectMapper() - @Test fun `test UByte`() { - val json = mapper.writeValueAsString(UByte.MAX_VALUE) - val deserialized = mapper.readValue(json) + val json = defaultMapper.writeValueAsString(UByte.MAX_VALUE) + val deserialized = defaultMapper.readValue(json) assertEquals(UByte.MAX_VALUE, deserialized) } @Test fun `test UByte overflow`() { - val json = mapper.writeValueAsString(UByte.MAX_VALUE + 1u) - assertThrows { mapper.readValue(json) } + val json = defaultMapper.writeValueAsString(UByte.MAX_VALUE + 1u) + assertThrows { defaultMapper.readValue(json) } } @Test fun `test UByte underflow`() { - val json = mapper.writeValueAsString(-1) - assertThrows { mapper.readValue(json) } + val json = defaultMapper.writeValueAsString(-1) + assertThrows { defaultMapper.readValue(json) } } @Test fun `test UShort`() { - val json = mapper.writeValueAsString(UShort.MAX_VALUE) - val deserialized = mapper.readValue(json) + val json = defaultMapper.writeValueAsString(UShort.MAX_VALUE) + val deserialized = defaultMapper.readValue(json) assertEquals(UShort.MAX_VALUE, deserialized) } @Test fun `test UShort overflow`() { - val json = mapper.writeValueAsString(UShort.MAX_VALUE + 1u) - assertThrows { mapper.readValue(json) } + val json = defaultMapper.writeValueAsString(UShort.MAX_VALUE + 1u) + assertThrows { defaultMapper.readValue(json) } } @Test fun `test UShort underflow`() { - val json = mapper.writeValueAsString(-1) - assertThrows { mapper.readValue(json) } + val json = defaultMapper.writeValueAsString(-1) + assertThrows { defaultMapper.readValue(json) } } @Test fun `test UInt`() { - val json = mapper.writeValueAsString(UInt.MAX_VALUE) - val deserialized = mapper.readValue(json) + val json = defaultMapper.writeValueAsString(UInt.MAX_VALUE) + val deserialized = defaultMapper.readValue(json) assertEquals(UInt.MAX_VALUE, deserialized) } @Test fun `test UInt overflow`() { - val json = mapper.writeValueAsString(UInt.MAX_VALUE.toULong() + 1u) - assertThrows { mapper.readValue(json) } + val json = defaultMapper.writeValueAsString(UInt.MAX_VALUE.toULong() + 1u) + assertThrows { defaultMapper.readValue(json) } } @Test fun `test UInt underflow`() { - val json = mapper.writeValueAsString(-1) - assertThrows { mapper.readValue(json) } + val json = defaultMapper.writeValueAsString(-1) + assertThrows { defaultMapper.readValue(json) } } @Test fun `test ULong`() { - val json = mapper.writeValueAsString(ULong.MAX_VALUE) - val deserialized = mapper.readValue(json) + val json = defaultMapper.writeValueAsString(ULong.MAX_VALUE) + val deserialized = defaultMapper.readValue(json) assertEquals(ULong.MAX_VALUE, deserialized) } @Test fun `test ULong overflow`() { val value = BigInteger(ULong.MAX_VALUE.toString()) + BigInteger.ONE - val json = mapper.writeValueAsString(value) - assertThrows { mapper.readValue(json) } + val json = defaultMapper.writeValueAsString(value) + assertThrows { defaultMapper.readValue(json) } } @Test fun `test ULong underflow`() { - val json = mapper.writeValueAsString(-1) - assertThrows { mapper.readValue(json) } + val json = defaultMapper.writeValueAsString(-1) + assertThrows { defaultMapper.readValue(json) } } } diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/VarargDeserTest.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/VarargDeserTest.kt index cf6fb24c3..51d399921 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/VarargDeserTest.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/VarargDeserTest.kt @@ -1,35 +1,33 @@ package com.fasterxml.jackson.module.kotlin.test -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.readValue - import org.junit.jupiter.api.Assertions.assertEquals - import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.Nested import org.junit.jupiter.api.Test // from https://github.com/ProjectMapK/jackson-module-kogera/blob/7872116052c9a4744c6d4e84ddd5cab6bb525024/src/test/kotlin/io/github/projectmapk/jackson/module/kogera/zIntegration/deser/VarargTest.kt class VarargDeserTest { - val mapper = jacksonObjectMapper() - class OnlyVararg(vararg val v: Int) @Nested inner class OnlyVarargTest { @Test fun hasArgs() { - val r = mapper.readValue("""{"v":[1,2,3]}""") + val r = defaultMapper.readValue("""{"v":[1,2,3]}""") assertEquals(listOf(1, 2, 3), r.v.asList()) } @Test fun empty() { - val r = mapper.readValue("""{"v":[]}""") + val r = defaultMapper.readValue("""{"v":[]}""") assertTrue(r.v.isEmpty()) } @Test fun undefined() { - val r = mapper.readValue("""{}""") + val r = defaultMapper.readValue("""{}""") assertTrue(r.v.isEmpty()) } } @@ -40,21 +38,21 @@ class VarargDeserTest { inner class HeadVarargTest { @Test fun hasArgs() { - val r = mapper.readValue("""{"i":0,"v":[1,2,null]}""") + val r = defaultMapper.readValue("""{"i":0,"v":[1,2,null]}""") assertEquals(listOf(1, 2, null), r.v.asList()) assertEquals(0, r.i) } @Test fun empty() { - val r = mapper.readValue("""{"i":0,"v":[]}""") + val r = defaultMapper.readValue("""{"i":0,"v":[]}""") assertTrue(r.v.isEmpty()) assertEquals(0, r.i) } @Test fun undefined() { - val r = mapper.readValue("""{"i":0}""") + val r = defaultMapper.readValue("""{"i":0}""") assertTrue(r.v.isEmpty()) assertEquals(0, r.i) } @@ -66,21 +64,21 @@ class VarargDeserTest { inner class TailVarargTest { @Test fun hasArgs() { - val r = mapper.readValue("""{"i":0,"v":["foo","bar","baz"]}""") + val r = defaultMapper.readValue("""{"i":0,"v":["foo","bar","baz"]}""") assertEquals(listOf("foo", "bar", "baz"), r.v.asList()) assertEquals(0, r.i) } @Test fun empty() { - val r = mapper.readValue("""{"i":0,"v":[]}""") + val r = defaultMapper.readValue("""{"i":0,"v":[]}""") assertTrue(r.v.isEmpty()) assertEquals(0, r.i) } @Test fun undefined() { - val r = mapper.readValue("""{"i":0}""") + val r = defaultMapper.readValue("""{"i":0}""") assertTrue(r.v.isEmpty()) assertEquals(0, r.i) } @@ -92,19 +90,19 @@ class VarargDeserTest { inner class HasDefaultVarargTest { @Test fun hasArgs() { - val r = mapper.readValue("""{"v":["foo","bar",null]}""") + val r = defaultMapper.readValue("""{"v":["foo","bar",null]}""") assertEquals(listOf("foo", "bar", null), r.v.asList()) } @Test fun empty() { - val r = mapper.readValue("""{"v":[]}""") + val r = defaultMapper.readValue("""{"v":[]}""") assertTrue(r.v.isEmpty()) } @Test fun undefined() { - val r = mapper.readValue("""{}""") + val r = defaultMapper.readValue("""{}""") assertEquals(listOf("foo", "bar"), r.v.asList()) } } diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/GitHub618.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/GitHub618.kt index e9329d3fe..de5a814cd 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/GitHub618.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/GitHub618.kt @@ -4,7 +4,7 @@ import com.fasterxml.jackson.core.JsonGenerator import com.fasterxml.jackson.databind.SerializerProvider import com.fasterxml.jackson.databind.annotation.JsonSerialize import com.fasterxml.jackson.databind.ser.std.StdSerializer -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import org.junit.jupiter.api.Test import kotlin.test.assertEquals @@ -23,8 +23,7 @@ class GitHub618 { @Test fun test() { - val mapper = jacksonObjectMapper() // expected: {"v":null}, but NullPointerException thrown - assertEquals("""{"v":null}""", mapper.writeValueAsString(D(null))) + assertEquals("""{"v":null}""", defaultMapper.writeValueAsString(D(null))) } } diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/GitHub625.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/GitHub625.kt index 1e74db789..01dc062e1 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/GitHub625.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/GitHub625.kt @@ -1,7 +1,7 @@ package com.fasterxml.jackson.module.kotlin.test.github import com.fasterxml.jackson.annotation.JsonInclude -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import org.junit.jupiter.api.Test import kotlin.test.assertEquals import kotlin.test.assertNotEquals @@ -29,9 +29,8 @@ class GitHub625 { @Test fun test() { - val mapper = jacksonObjectMapper() val dto = Dto() - assertEquals("{}", mapper.writeValueAsString(dto)) + assertEquals("{}", defaultMapper.writeValueAsString(dto)) } @JsonInclude(value = JsonInclude.Include.NON_EMPTY, content = JsonInclude.Include.NON_NULL) @@ -47,8 +46,7 @@ class GitHub625 { @Test fun failing() { - val writer = jacksonObjectMapper() - val json = writer.writeValueAsString(FailingDto()) + val json = defaultMapper.writeValueAsString(FailingDto()) assertNotEquals("{}", json) } diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/GitHub844.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/GitHub844.kt index dbaa4c744..a99bfa349 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/GitHub844.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/GitHub844.kt @@ -1,9 +1,8 @@ package com.fasterxml.jackson.module.kotlin.test.github import com.fasterxml.jackson.annotation.JsonTypeInfo -import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.readValue -import com.fasterxml.jackson.module.kotlin.registerKotlinModule import org.junit.jupiter.api.Test import kotlin.test.assertEquals @@ -22,8 +21,7 @@ class GitHub844 { } """ - val jacksonObjectMapper = ObjectMapper().registerKotlinModule() - val message = jacksonObjectMapper.readValue(json) + val message = defaultMapper.readValue(json) assertEquals(ChildClass("Test"), message) } diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/GitHub876.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/GitHub876.kt index d3c419426..2911fb5c1 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/GitHub876.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/GitHub876.kt @@ -3,6 +3,7 @@ package com.fasterxml.jackson.module.kotlin.test.github import com.fasterxml.jackson.annotation.JsonSetter import com.fasterxml.jackson.annotation.Nulls import com.fasterxml.jackson.module.kotlin.configOverride +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper import com.fasterxml.jackson.module.kotlin.readValue import org.junit.jupiter.api.Nested @@ -21,14 +22,12 @@ class GitHub876 { @Nested inner class WithAnnotationWithoutDefaultTest { - val mapper = jacksonObjectMapper() - @Test fun nullInput() { val input = """{"list": null, "map": null, "string": null}""" val expected = WithAnnotationWithoutDefault(emptyList(), emptyMap(), "") - val actual = mapper.readValue(input) + val actual = defaultMapper.readValue(input) assertEquals(expected, actual) } @@ -38,7 +37,7 @@ class GitHub876 { val input = """{}""" val expected = WithAnnotationWithoutDefault(emptyList(), emptyMap(), "") - val actual = mapper.readValue(input) + val actual = defaultMapper.readValue(input) assertEquals(expected, actual) } @@ -55,15 +54,13 @@ class GitHub876 { @Nested inner class WithAnnotationWithDefaultTest { - val mapper = jacksonObjectMapper() - @Test fun nullInput() { // If null is explicitly specified, the default value is not used val input = """{"list": null, "map": null, "string": null}""" val expected = WithAnnotationWithDefault(emptyList(), emptyMap(), "") - val actual = mapper.readValue(input) + val actual = defaultMapper.readValue(input) assertEquals(expected, actual) } @@ -74,7 +71,7 @@ class GitHub876 { val input = """{}""" val expected = WithAnnotationWithDefault() - val actual = mapper.readValue(input) + val actual = defaultMapper.readValue(input) assertEquals(expected, actual) } diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github104.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github104.kt index 4272e6d6d..3402dc86e 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github104.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github104.kt @@ -1,6 +1,6 @@ package com.fasterxml.jackson.module.kotlin.test.github -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.readValue import org.junit.jupiter.api.Test @@ -13,10 +13,8 @@ class TestGithub104 { @Test fun testIt() { - val objectMapper = jacksonObjectMapper() - val jsonValue = """{"name":"TestName"}""" - objectMapper.readValue(jsonValue) + defaultMapper.readValue(jsonValue) } -} \ No newline at end of file +} diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github114.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github114.kt index 850465abb..a18d147b3 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github114.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github114.kt @@ -2,7 +2,7 @@ package com.fasterxml.jackson.module.kotlin.test.github import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.readValue import org.junit.jupiter.api.Test import kotlin.test.assertEquals @@ -23,20 +23,17 @@ class TestGithub114 { @Test fun testCompanionObjectCreatorWithDefaultParameters() { - val mapper = jacksonObjectMapper() - - val foo = mapper.readValue("""{"baz": "bazValue"}""") + val foo = defaultMapper.readValue("""{"baz": "bazValue"}""") println(foo) - val fooWithStaticCreator = mapper.readValue("""{"baz": "bazValue"}""") + val fooWithStaticCreator = defaultMapper.readValue("""{"baz": "bazValue"}""") println(fooWithStaticCreator) // Expect FooWithStaticCreator(bar=default, baz=bazValue), result == MismatchedInputException: Missing required creator property 'bar' (index 0) assertEquals(FooWithStaticCreator(FooWithStaticCreator.someValue, "bazValue"), fooWithStaticCreator) } @Test fun otherTestVariation() { - val mapper = jacksonObjectMapper() - val testObj = mapper.readValue("""{"id":1}""") + val testObj = defaultMapper.readValue("""{"id":1}""") assertEquals("yes", testObj.prop) } diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github120.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github120.kt index f00c068bf..3ff323d0d 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github120.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github120.kt @@ -2,7 +2,7 @@ package com.fasterxml.jackson.module.kotlin.test.github import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonValue -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import org.junit.jupiter.api.Test import kotlin.test.assertEquals @@ -18,13 +18,12 @@ class TestGithub120 { @Test fun testNestedJsonValue() { - val om = jacksonObjectMapper() val foo = Foo(4711L) val bar = Bar(foo) - val asString = om.writeValueAsString(bar) + val asString = defaultMapper.writeValueAsString(bar) assertEquals("{\"foo\":4711}", asString) - val fromString = om.readValue(asString, Bar::class.java) + val fromString = defaultMapper.readValue(asString, Bar::class.java) assertEquals(bar, fromString) } } diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github124.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github124.kt index 5db277bf3..24550a3fd 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github124.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github124.kt @@ -3,7 +3,7 @@ package com.fasterxml.jackson.module.kotlin.test.github import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonIgnore import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.readValue import org.junit.jupiter.api.Test @@ -11,17 +11,15 @@ class TestGithub124 { // test for [module-kotlin#124]: broken in 2.9.3, fixed in 2.9.6 @Test fun test() { - val objMapper = jacksonObjectMapper() - // with 2.9.3 prints // Foo(name=foo, query=NonSerializable, rawQuery=bar) // but with 2.9.4 throws: // com.fasterxml.jackson.module.kotlin.MissingKotlinParameterException: Instantiation of [simple type, class DeserializationTest$Foo] value failed for JSON property query due to missing (therefore NULL) value for creator parameter rawQuery which is a non-nullable type // at [Source: (String)"{"name": "foo", "query": "bar"}"; line: 1, column: 31] (through reference chain: DeserializationTest$Foo["query"]) - val deserialized: Foo = objMapper.readValue("{\"name\": \"foo\", \"query\": \"bar\"}") + val deserialized: Foo = defaultMapper.readValue("{\"name\": \"foo\", \"query\": \"bar\"}") println(deserialized) - val serialized = objMapper.writeValueAsString(deserialized) + val serialized = defaultMapper.writeValueAsString(deserialized) // with 2.9.3 prints // {"name":"foo","query":"bar"} @@ -39,4 +37,4 @@ class TestGithub124 { constructor(@JsonProperty("name") name: String, @JsonProperty("query") rawQuery: String): this(name, NonSerializable(rawQuery), rawQuery) } -} \ No newline at end of file +} diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github131.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github131.kt index 6d73abe65..dcb3b4a53 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github131.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github131.kt @@ -1,6 +1,6 @@ package com.fasterxml.jackson.module.kotlin.test.github -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.readValue import org.junit.jupiter.api.Test import kotlin.test.assertEquals @@ -12,8 +12,7 @@ class TestGithub131 { @Test fun testFailureCase() { - val mapper = jacksonObjectMapper() - val x = mapper.readValue("""{"name":"abc"}""") + val x = defaultMapper.readValue("""{"name":"abc"}""") assertEquals(DerivedClass("abc").name, x.name) } -} \ No newline at end of file +} diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github145.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github145.kt index 126f20283..96fb30491 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github145.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github145.kt @@ -3,14 +3,12 @@ package com.fasterxml.jackson.module.kotlin.test.github import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.databind.ObjectMapper -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.readValue import org.junit.jupiter.api.Test @Suppress("UNUSED_VARIABLE") class TestGithub145 { - private val objectMapper = jacksonObjectMapper() - @Test fun workingTestWithoutKotlinModule() { class Person1( @@ -42,8 +40,8 @@ class TestGithub145 { ) } - val person1String = objectMapper.readValue(""""TestPreName,TestLastname"""") - val person1Json = objectMapper.readValue("""{"preName":"TestPreName","lastName":"TestLastname"}""") + val person1String = defaultMapper.readValue(""""TestPreName,TestLastname"""") + val person1Json = defaultMapper.readValue("""{"preName":"TestPreName","lastName":"TestLastname"}""") } @Test @@ -56,8 +54,8 @@ class TestGithub145 { ) } - val person2String = objectMapper.readValue(""""TestPreName,TestLastname"""") - val person2Json = objectMapper.readValue("""{"preName":"TestPreName","lastName":"TestLastname"}""") + val person2String = defaultMapper.readValue(""""TestPreName,TestLastname"""") + val person2Json = defaultMapper.readValue("""{"preName":"TestPreName","lastName":"TestLastname"}""") } @Test @@ -72,7 +70,7 @@ class TestGithub145 { } } - val person4String = objectMapper.readValue(""""TestPreName,TestLastname"""") + val person4String = defaultMapper.readValue(""""TestPreName,TestLastname"""") // person4 does not have parameter bound constructor, only string } @@ -87,8 +85,8 @@ class TestGithub145 { this(preNameAndLastName.substringBefore(","), preNameAndLastName.substringAfter(",")) } - val person5String = objectMapper.readValue(""""TestPreName,TestLastname"""") - val person5Json = objectMapper.readValue("""{"preName":"TestPreName","lastName":"TestLastname"}""") + val person5String = defaultMapper.readValue(""""TestPreName,TestLastname"""") + val person5Json = defaultMapper.readValue("""{"preName":"TestPreName","lastName":"TestLastname"}""") } // Cannot have companion object in class declared within function @@ -115,8 +113,8 @@ class TestGithub145 { @Test fun testPerson6() { - val person6String = objectMapper.readValue(""""TestPreName,TestLastname"""") - val person6Json = objectMapper.readValue("""{"preName":"TestPreName","lastName":"TestLastname"}""") + val person6String = defaultMapper.readValue(""""TestPreName,TestLastname"""") + val person6Json = defaultMapper.readValue("""{"preName":"TestPreName","lastName":"TestLastname"}""") } } diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github148.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github148.kt index b44504f8b..a9204e570 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github148.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github148.kt @@ -1,6 +1,6 @@ package com.fasterxml.jackson.module.kotlin.test.github -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import org.junit.jupiter.api.Nested import org.junit.jupiter.api.Test import kotlin.test.assertEquals @@ -35,16 +35,14 @@ class TestGithub148 { @Nested inner class DemoApplicationTests { - val objectMapper = jacksonObjectMapper() - @Test fun correntBean() { - assertEquals("{\"name\":\"corrent\",\"type\":\"TYPEA\"}", objectMapper.writeValueAsString(CorrentBean("corrent", CorrectType.TYPEA))) + assertEquals("{\"name\":\"corrent\",\"type\":\"TYPEA\"}", defaultMapper.writeValueAsString(CorrentBean("corrent", CorrectType.TYPEA))) } @Test fun incorrentBean() { - assertEquals("{\"name\":\"incorrent\",\"type\":\"TYPEA\"}", objectMapper.writeValueAsString(IncorrentBean("incorrent", IncorrectType.TYPEA))) + assertEquals("{\"name\":\"incorrent\",\"type\":\"TYPEA\"}", defaultMapper.writeValueAsString(IncorrentBean("incorrent", IncorrectType.TYPEA))) } } } diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github149.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github149.kt index 1c6d78f8e..2777420b2 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github149.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github149.kt @@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonAutoDetect import com.fasterxml.jackson.annotation.JsonBackReference import com.fasterxml.jackson.annotation.JsonManagedReference import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper import org.junit.jupiter.api.Test @@ -76,12 +77,11 @@ class TestGithub149 { @Test fun testGithub129(){ - val mapper = jacksonObjectMapper() val c = Car(id = 100) val color = Color(id = 100, code = "#FFFFF").apply { car = c } c.colors.add(color) - val s = mapper.writeValueAsString(c) - val value = mapper.readValue(s, Car::class.java) + val s = defaultMapper.writeValueAsString(c) + val value = defaultMapper.readValue(s, Car::class.java) // print(value) } } diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github15.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github15.kt index 5836adf91..855f3eaa5 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github15.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github15.kt @@ -6,21 +6,21 @@ import kotlin.test.assertEquals class TestGithub15 { @Test fun testEnumConstructorWithParm() { - val one = jacksonObjectMapper().readValue("\"ONE\"", TestEnum::class.java) + val one = defaultMapper.readValue("\"ONE\"", TestEnum::class.java) assertEquals(TestEnum.ONE, one) - val two = jacksonObjectMapper().readValue("\"TWO\"", TestEnum::class.java) + val two = defaultMapper.readValue("\"TWO\"", TestEnum::class.java) assertEquals(TestEnum.TWO, two) } @Test fun testNormEnumWithoutParam() { - val one = jacksonObjectMapper().readValue("\"ONE\"", TestOther::class.java) + val one = defaultMapper.readValue("\"ONE\"", TestOther::class.java) assertEquals(TestOther.ONE, one) - val two = jacksonObjectMapper().readValue("\"TWO\"", TestOther::class.java) + val two = defaultMapper.readValue("\"TWO\"", TestOther::class.java) assertEquals(TestOther.TWO, two) } @Test fun testClassWithEnumsNeedingConstruction() { - val obj: UsingEnum = jacksonObjectMapper().readValue("""{"x":"ONE","y":"TWO"}""") + val obj: UsingEnum = defaultMapper.readValue("""{"x":"ONE","y":"TWO"}""") assertEquals(TestEnum.ONE, obj.x) assertEquals(TestOther.TWO, obj.y) } diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github155.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github155.kt index d82fd6b2f..a1f2e78d9 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github155.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github155.kt @@ -1,7 +1,7 @@ package com.fasterxml.jackson.module.kotlin.test.github import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.readValue import org.junit.jupiter.api.Test @@ -14,9 +14,8 @@ class TestGithub155 { @Test fun testGithub155() { - jacksonObjectMapper().readValue(""" + defaultMapper.readValue(""" {"name":"fred","age":12,"country":"Libertad","city":"Northville"} """.trimIndent()) - } -} \ No newline at end of file +} diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github158.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github158.kt index 0763fefca..be364ce1c 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github158.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github158.kt @@ -1,7 +1,7 @@ package com.fasterxml.jackson.module.kotlin.test.github import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.readValue import org.junit.jupiter.api.Test import kotlin.test.assertEquals @@ -20,13 +20,11 @@ class TestGithub158 { @Test fun testEnumSerDeser() { - val mapper = jacksonObjectMapper() - val original = SampleContainer(SampleImpl.One) - val json = mapper.writeValueAsString(original) + val json = defaultMapper.writeValueAsString(original) // println(json) - val obj = mapper.readValue(json) + val obj = defaultMapper.readValue(json) assertEquals(original, obj) } } diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github165.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github165.kt index ce054964e..2eec404c8 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github165.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github165.kt @@ -2,7 +2,7 @@ package com.fasterxml.jackson.module.kotlin.test.github import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.annotation.JsonSetter -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.readValue import org.junit.jupiter.api.Test import kotlin.test.assertEquals @@ -34,7 +34,7 @@ class TestGithub165 { @Test fun testJsonSetterCalledKotlin() { - val obj = jacksonObjectMapper().readValue("""{"name":"Fred","year":"1942"}""") + val obj = defaultMapper.readValue("""{"name":"Fred","year":"1942"}""") assertEquals("1942", obj.showYear) assertEquals("Fred", obj.showName) assertTrue(obj.yearSetterCalled) @@ -43,10 +43,10 @@ class TestGithub165 { @Test fun testJsonSetterCalledJava() { - val obj = jacksonObjectMapper().readValue("""{"name":"Fred","year":"1942"}""") + val obj = defaultMapper.readValue("""{"name":"Fred","year":"1942"}""") assertEquals("1942", obj.showYear) assertEquals("Fred", obj.showName) assertTrue(obj.yearSetterCalled) assertFalse(obj.nameSetterCalled) } -} \ No newline at end of file +} diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github167.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github167.kt index 854d5cc47..9fd817e30 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github167.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github167.kt @@ -1,11 +1,10 @@ package com.fasterxml.jackson.module.kotlin.test.github import com.fasterxml.jackson.databind.ObjectMapper -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import org.junit.jupiter.api.Test import java.util.function.IntSupplier - class TestGithub167 { val samObject = IntSupplier { 42 } @@ -14,12 +13,12 @@ class TestGithub167 { @Test fun withKotlinExtension() { - jacksonObjectMapper().writeValueAsString(samObject) + defaultMapper.writeValueAsString(samObject) } @Test fun withKotlinExtension_Synthetic() { - jacksonObjectMapper().writeValueAsString(samObjectSynthetic) + defaultMapper.writeValueAsString(samObjectSynthetic) } @@ -32,4 +31,4 @@ class TestGithub167 { fun withoutKotlinExtension_Synthetic() { ObjectMapper().writeValueAsString(samObjectSynthetic) } -} \ No newline at end of file +} diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github168.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github168.kt index 29d31995f..64c16c45c 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github168.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github168.kt @@ -2,7 +2,7 @@ package com.fasterxml.jackson.module.kotlin.test.github import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.module.kotlin.MissingKotlinParameterException -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.readValue import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertThrows @@ -14,21 +14,21 @@ class TestGithub168 { @Test fun testIfRequiredIsReallyRequiredWhenNullUsed() { - val obj = jacksonObjectMapper().readValue("""{"foo":null,"baz":"whatever"}""") + val obj = defaultMapper.readValue("""{"foo":null,"baz":"whatever"}""") assertEquals("whatever", obj.baz) } @Test fun testIfRequiredIsReallyRequiredWhenAbsent() { assertThrows { - val obj = jacksonObjectMapper().readValue("""{"baz":"whatever"}""") + val obj = defaultMapper.readValue("""{"baz":"whatever"}""") assertEquals("whatever", obj.baz) } } @Test fun testIfRequiredIsReallyRequiredWhenValuePresent() { - val obj = jacksonObjectMapper().readValue("""{"foo":"yay!","baz":"whatever"}""") + val obj = defaultMapper.readValue("""{"foo":"yay!","baz":"whatever"}""") assertEquals("whatever", obj.baz) } } diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github179.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github179.kt index 794b925e9..e25394d32 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github179.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github179.kt @@ -2,7 +2,7 @@ package com.fasterxml.jackson.module.kotlin.test.github import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.readValue import org.junit.jupiter.api.Test import kotlin.test.assertEquals @@ -10,24 +10,22 @@ import kotlin.test.assertEquals // verifying work around for this issue, no bug present class TestGithub179 { - val objectMapper = jacksonObjectMapper() - @Test fun listOfStrings() { - val strings = objectMapper.readValue("""[ "first", "second" ]""") + val strings = defaultMapper.readValue("""[ "first", "second" ]""") assertEquals(strings.values, listOf("first", "second")) } @Test fun embeddedListOfStrings() { - val stringsContainer = objectMapper.readValue( + val stringsContainer = defaultMapper.readValue( """{ "strings" : [ "first", "second" ] }""") assertEquals(stringsContainer.strings.values, listOf("first", "second")) } @Test fun embeddedListOfEnums() { - val myEnumsContainer = objectMapper.readValue( + val myEnumsContainer = defaultMapper.readValue( """{ "myEnums" : [ "first", "second" ] }""") assertEquals(myEnumsContainer.myEnums.values, listOf(MyEnum.FIRST, MyEnum.SECOND)) } @@ -44,4 +42,4 @@ class TestGithub179 { @JsonProperty("first") FIRST, @JsonProperty("second") SECOND } -} \ No newline at end of file +} diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github180.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github180.kt index f7d565f80..b66d1412c 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github180.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github180.kt @@ -2,7 +2,7 @@ package com.fasterxml.jackson.module.kotlin.test.github import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.readValue import org.junit.jupiter.api.Test import kotlin.test.assertNull @@ -24,7 +24,7 @@ class TestGithub180 { @Test fun testMissingProperty() { - val obj = jacksonObjectMapper().readValue("""{}""") + val obj = defaultMapper.readValue("""{}""") assertNull(obj.instantName) assertNull(obj.someInt) } diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github181.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github181.kt index df3ad5ea8..c7018f2d3 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github181.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github181.kt @@ -1,7 +1,7 @@ package com.fasterxml.jackson.module.kotlin.test.github import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.readValue import org.junit.jupiter.api.Test import kotlin.test.assertEquals @@ -21,9 +21,9 @@ class TestGithub181 { @Test fun testReflectionExceptionOnDelegatedMap() { val testInstance = HealthStatusMap(mapOf("failed" to HealthStatus.FAILED, "okey dokey" to HealthStatus.OK)) - val json = jacksonObjectMapper().writeValueAsString(testInstance) + val json = defaultMapper.writeValueAsString(testInstance) assertEquals("{\"failed\":\"FAILED\",\"okey dokey\":\"OK\"}", json) - val newInstance = jacksonObjectMapper().readValue(json) + val newInstance = defaultMapper.readValue(json) assertEquals(testInstance, newInstance) } -} \ No newline at end of file +} diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github194.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github194.kt index 85316bdc6..2903b35f6 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github194.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github194.kt @@ -2,7 +2,7 @@ package com.fasterxml.jackson.module.kotlin.test.github import com.fasterxml.jackson.annotation.JsonIdentityInfo import com.fasterxml.jackson.annotation.ObjectIdGenerators -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import org.junit.jupiter.api.Test import java.util.UUID import kotlin.test.assertEquals @@ -13,8 +13,7 @@ class TestGithub194 { @Test fun testIdentityInfo() { - val mapper = jacksonObjectMapper() - val value = mapper.readValue(json, WithIdentity::class.java) + val value = defaultMapper.readValue(json, WithIdentity::class.java) assertEquals(id, value.id) assertEquals(id.toString(), value.idString) assertEquals("Foo", value.name) @@ -31,8 +30,7 @@ class TestGithub194 { @Test fun testIdentityInfo_WithDefaultId() { - val mapper = jacksonObjectMapper() - val value = mapper.readValue(json, WithIdentityAndDefaultId::class.java) + val value = defaultMapper.readValue(json, WithIdentityAndDefaultId::class.java) assertEquals(id, value.id) assertEquals(id.toString(), value.idString) assertEquals("Foo", value.name) diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github196.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github196.kt index 0f2a78180..b04174570 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github196.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github196.kt @@ -1,6 +1,6 @@ package com.fasterxml.jackson.module.kotlin.test.github -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.readValue import org.junit.jupiter.api.Test import kotlin.test.assertSame @@ -11,6 +11,6 @@ import kotlin.test.assertSame class TestGithub196 { @Test fun testUnitSingletonDeserialization() { - assertSame(jacksonObjectMapper().readValue("{}"), Unit) + assertSame(defaultMapper.readValue("{}"), Unit) } } diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github210.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github210.kt index e883840c4..a70168ae5 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github210.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github210.kt @@ -1,6 +1,6 @@ package com.fasterxml.jackson.module.kotlin.test.github -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.readValue import org.junit.jupiter.api.Test @@ -12,21 +12,19 @@ class TestGithub210 { class ExampleNoFail(val regexItem: RegexLike, val stringItem: String) class RegexLike(val pattern: String, val options: List) - val mapper = jacksonObjectMapper() - @Test fun testSerDesOfRegex() { val happyJson = """{"stringItem":"hello","regexItem":{"options":[],"pattern":"test"}}""" val troubleJson = """{"regexItem":{"options":[],"pattern":"test"},"stringItem":"hello"}""" - mapper.readValue(happyJson) - mapper.readValue(troubleJson) + defaultMapper.readValue(happyJson) + defaultMapper.readValue(troubleJson) - mapper.readValue(happyJson) - mapper.readValue(happyJson) + defaultMapper.readValue(happyJson) + defaultMapper.readValue(happyJson) // the following used to fail on stringItem being missing, the KotlinValueInstantiator is confused - mapper.readValue(troubleJson) // fail {"regexItem":{"pattern":"test","options":[]},"stringItem":"hello"} - mapper.readValue(troubleJson) // fail {"regexItem":{"pattern":"test","options":[]},"stringItem":"hello"} + defaultMapper.readValue(troubleJson) // fail {"regexItem":{"pattern":"test","options":[]},"stringItem":"hello"} + defaultMapper.readValue(troubleJson) // fail {"regexItem":{"pattern":"test","options":[]},"stringItem":"hello"} } -} \ No newline at end of file +} diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github22.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github22.kt index 076d8f651..f946a48a8 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github22.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github22.kt @@ -2,7 +2,7 @@ package com.fasterxml.jackson.module.kotlin.test.github import com.fasterxml.jackson.annotation.JsonIgnore import com.fasterxml.jackson.annotation.JsonValue -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.readValue import org.junit.jupiter.api.Test import kotlin.test.assertEquals @@ -22,10 +22,10 @@ class TestGithub22 { val expectedJson = "\"test\"" val expectedObj = StringValue("test") - val actualJson = jacksonObjectMapper().writeValueAsString(expectedObj) + val actualJson = defaultMapper.writeValueAsString(expectedObj) assertEquals(expectedJson, actualJson) - val actualObj = jacksonObjectMapper().readValue("\"test\"") + val actualObj = defaultMapper.readValue("\"test\"") assertEquals(expectedObj.other, actualObj.other) } @@ -34,10 +34,10 @@ class TestGithub22 { val expectedJson = "\"test\"" val expectedObj = StringValue2("test") - val actualJson = jacksonObjectMapper().writeValueAsString(expectedObj) + val actualJson = defaultMapper.writeValueAsString(expectedObj) assertEquals(expectedJson, actualJson) - val actualObj = jacksonObjectMapper().readValue("\"test\"") + val actualObj = defaultMapper.readValue("\"test\"") assertEquals(expectedObj, actualObj) } diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github25.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github25.kt index cc30f9d98..26ad36c61 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github25.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github25.kt @@ -25,14 +25,14 @@ class TestGithub25 { } @Test fun testSerWithDelegates() { - val json = jacksonObjectMapper().writeValueAsString(SomethingWithDelegates(linkedMapOf("otherData1" to "1", "otherData2" to "2", "otherData3" to "3")) + val json = defaultMapper.writeValueAsString(SomethingWithDelegates(linkedMapOf("otherData1" to "1", "otherData2" to "2", "otherData3" to "3")) .withOtherData("exists")) assertEquals("""{"data":{"otherData1":"1","otherData2":"2","otherData3":"3"},"changeable":"starting value","name":"fred","somethingNotNull":"exists"}""", json) } @Test fun testDeserWithDelegates() { val json = """{"changeable":"new value","data":{"otherData1":"1","otherData2":"2","otherData3":"3"},"somethingNotNull":"exists"}""" - val obj: SomethingWithDelegates = jacksonObjectMapper().readValue(json) + val obj: SomethingWithDelegates = defaultMapper.readValue(json) assertEquals("fred", obj.name) // not set by the Json, isn't in the constructor and is read only delegate assertEquals("ignored", obj.ignoreMe) assertEquals("new value", obj.changeable) @@ -42,4 +42,4 @@ class TestGithub25 { assertEquals("exists", obj.somethingNotNull) } -} \ No newline at end of file +} diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github26.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github26.kt index 3ef440c8f..3663d80a6 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github26.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github26.kt @@ -1,6 +1,6 @@ package com.fasterxml.jackson.module.kotlin.test.github -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.readValue import org.junit.jupiter.api.Test import kotlin.test.assertEquals @@ -9,18 +9,18 @@ data class ClassWithPrimitivesWithDefaults(val i: Int = 5, val x: Int) class TestGithub26 { @Test fun testConstructorWithPrimitiveTypesDefaultedExplicitlyAndImplicitly() { - val check1: ClassWithPrimitivesWithDefaults = jacksonObjectMapper().readValue("""{"i":3,"x":2}""") + val check1: ClassWithPrimitivesWithDefaults = defaultMapper.readValue("""{"i":3,"x":2}""") assertEquals(3, check1.i) assertEquals(2, check1.x) - val check2: ClassWithPrimitivesWithDefaults = jacksonObjectMapper().readValue("""{}""") + val check2: ClassWithPrimitivesWithDefaults = defaultMapper.readValue("""{}""") assertEquals(5, check2.i) assertEquals(0, check2.x) - val check3: ClassWithPrimitivesWithDefaults = jacksonObjectMapper().readValue("""{"i": 2}""") + val check3: ClassWithPrimitivesWithDefaults = defaultMapper.readValue("""{"i": 2}""") assertEquals(2, check3.i) assertEquals(0, check3.x) } -} \ No newline at end of file +} diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github269.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github269.kt index fe5aceb21..7fedb5014 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github269.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github269.kt @@ -3,7 +3,7 @@ package com.fasterxml.jackson.module.kotlin.test.github import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.databind.annotation.JsonSerialize import com.fasterxml.jackson.databind.ser.std.ToStringSerializer -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.readValue import org.junit.jupiter.api.Test import kotlin.test.assertEquals @@ -29,51 +29,43 @@ class TestGithub269 { @Test fun testGithub269WithFoo() { - val mapper = jacksonObjectMapper() - val testObject = Foo(Regex("test")) - val testJson = mapper.writeValueAsString(testObject) - val resultObject = mapper.readValue(testJson) + val testJson = defaultMapper.writeValueAsString(testObject) + val resultObject = defaultMapper.readValue(testJson) assertEquals(testObject.pattern.pattern, resultObject.pattern.pattern) assertEquals(testObject.pattern.options, resultObject.pattern.options) - mapper.readValue("""{"pattern":"test"}""") + defaultMapper.readValue("""{"pattern":"test"}""") } @Test fun testGithub269WithBar() { - val mapper = jacksonObjectMapper() - val testObject = Bar(Regex("test")) - val testJson = mapper.writeValueAsString(testObject) - val resultObject = mapper.readValue(testJson) + val testJson = defaultMapper.writeValueAsString(testObject) + val resultObject = defaultMapper.readValue(testJson) assertEquals(testObject.thing.pattern, resultObject.thing.pattern) assertEquals(testObject.thing.options, resultObject.thing.options) - mapper.readValue("""{"thing":"test"}""") + defaultMapper.readValue("""{"thing":"test"}""") } @Test fun testGithub269WithGoo() { - val mapper = jacksonObjectMapper() - val testObject = Goo(Regex("test_pattern_1")) - val testJson = mapper.writeValueAsString(testObject) - val resultObject = mapper.readValue(testJson) + val testJson = defaultMapper.writeValueAsString(testObject) + val resultObject = defaultMapper.readValue(testJson) assertEquals(testObject.myPattern.pattern, resultObject.myPattern.pattern) } @Test fun testGithub269WithZoo() { - val mapper = jacksonObjectMapper() - val testObject = Zoo(Regex("test_pattern_1")) - val testJson = mapper.writeValueAsString(testObject) - val resultObject = mapper.readValue(testJson) + val testJson = defaultMapper.writeValueAsString(testObject) + val resultObject = defaultMapper.readValue(testJson) assertEquals(testObject.myPattern.pattern, resultObject.myPattern.pattern) } -} \ No newline at end of file +} diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github270.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github270.kt index 3c4efe9a9..ed78f4613 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github270.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github270.kt @@ -1,6 +1,6 @@ package com.fasterxml.jackson.module.kotlin.test.github -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import org.junit.jupiter.api.Test import kotlin.test.assertEquals @@ -13,7 +13,7 @@ class TestGithub270 { @Test fun testPublicFieldOverlappingFunction() { - val json = jacksonObjectMapper().writeValueAsString(Wrapper("Hello")) + val json = defaultMapper.writeValueAsString(Wrapper("Hello")) assertEquals("""{"upper":"HELLO"}""", json) } } diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github29.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github29.kt index 2b4eb9f17..472a9e984 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github29.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github29.kt @@ -1,6 +1,6 @@ package com.fasterxml.jackson.module.kotlin.test.github -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.readValue import org.junit.jupiter.api.Test import kotlin.test.assertEquals @@ -9,12 +9,12 @@ class TestGithub29 { data class Github29TestObj(val name: String, val other: String = "test") @Test fun testDefaultValuesInDeser() { - val check1: Github29TestObj = jacksonObjectMapper().readValue("""{"name": "bla"}""") + val check1: Github29TestObj = defaultMapper.readValue("""{"name": "bla"}""") assertEquals("bla", check1.name) assertEquals("test", check1.other) - val check2: Github29TestObj = jacksonObjectMapper().readValue("""{"name": "bla", "other": "fish"}""") + val check2: Github29TestObj = defaultMapper.readValue("""{"name": "bla", "other": "fish"}""") assertEquals("bla", check2.name) assertEquals("fish", check2.other) } -} \ No newline at end of file +} diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github308.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github308.kt index d649197e7..dd54fa2be 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github308.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github308.kt @@ -3,7 +3,7 @@ package com.fasterxml.jackson.module.kotlin.test.github import com.fasterxml.jackson.annotation.JsonIgnore import com.fasterxml.jackson.annotation.JsonIgnoreProperties import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.readValue import org.junit.jupiter.api.Test import kotlin.test.assertEquals @@ -25,7 +25,7 @@ class TestGithub308 { @Test fun createTestDto() { - val dto: TestDto = jacksonObjectMapper().readValue("""{"id":12345}""") + val dto: TestDto = defaultMapper.readValue("""{"id":12345}""") assertNotNull(dto) assertNull(dto.id) diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github32.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github32.kt index c0f5c016e..1cacc9dad 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github32.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github32.kt @@ -2,7 +2,7 @@ package com.fasterxml.jackson.module.kotlin.test.github import com.fasterxml.jackson.databind.JsonMappingException import com.fasterxml.jackson.databind.exc.MismatchedInputException -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.readValue import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test @@ -10,7 +10,7 @@ import org.junit.jupiter.api.assertThrows private class TestGithub32 { @Test fun `valid mandatory data class constructor param`() { - jacksonObjectMapper().readValue(""" + defaultMapper.readValue(""" { "firstName": "James", "lastName": "Bond" @@ -22,7 +22,7 @@ private class TestGithub32 { val thrown = assertThrows( "MissingKotlinParameterException with missing `firstName` parameter" ) { - jacksonObjectMapper().readValue(""" + defaultMapper.readValue(""" { "lastName": "Bond" } @@ -36,7 +36,7 @@ private class TestGithub32 { @Test fun `null mandatory data class constructor param`() { val thrown = assertThrows { - jacksonObjectMapper().readValue(""" + defaultMapper.readValue(""" { "firstName": null, "lastName": "Bond" @@ -51,7 +51,7 @@ private class TestGithub32 { @Test fun `missing mandatory constructor param - nested in class with default constructor`() { val thrown = assertThrows { - jacksonObjectMapper().readValue(""" + defaultMapper.readValue(""" { "person": { "lastName": "Bond" @@ -67,7 +67,7 @@ private class TestGithub32 { @Test fun `missing mandatory constructor param - nested in class with single arg constructor`() { val thrown = assertThrows { - jacksonObjectMapper().readValue(""" + defaultMapper.readValue(""" { "person": { "lastName": "Bond" @@ -83,7 +83,7 @@ private class TestGithub32 { @Test fun `missing mandatory constructor param - nested in class with List arg constructor`() { val thrown = assertThrows { - jacksonObjectMapper().readValue(""" + defaultMapper.readValue(""" { "people": [ { diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github335.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github335.kt index 31e8dce3d..1a654edfa 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github335.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github335.kt @@ -5,14 +5,12 @@ import com.fasterxml.jackson.annotation.JsonSubTypes.Type import com.fasterxml.jackson.annotation.JsonTypeInfo import com.fasterxml.jackson.annotation.JsonTypeInfo.As import com.fasterxml.jackson.annotation.JsonTypeInfo.Id -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.readValue import org.junit.jupiter.api.Test import kotlin.test.assertEquals class Github335Test { - val mapper = jacksonObjectMapper() - interface Payload data class UniquePayload(val data: String) : Payload @@ -26,8 +24,8 @@ class Github335Test { @Test fun serializeAndDeserializeTypeable() { val oldEntity = MyEntity(null, null) - val json = mapper.writeValueAsString(oldEntity) - val newEntity = mapper.readValue(json) + val json = defaultMapper.writeValueAsString(oldEntity) + val newEntity = defaultMapper.readValue(json) assertEquals(oldEntity, newEntity) } diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github356.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github356.kt index 8b3ff353e..e19e349f3 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github356.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github356.kt @@ -1,19 +1,17 @@ package com.fasterxml.jackson.module.kotlin.test.github import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.readValue import org.junit.jupiter.api.Test import kotlin.test.assertEquals class TestGithub356 { - private val mapper = jacksonObjectMapper() - @Test fun deserializeInlineClass() { assertEquals( ClassWithInlineMember(InlineClass("bar")), - mapper.readValue("""{"inlineClassProperty":"bar"}""") + defaultMapper.readValue("""{"inlineClassProperty":"bar"}""") ) } @@ -21,7 +19,7 @@ class TestGithub356 { fun serializeInlineClass() { assertEquals( """{"inlineClassProperty":"bar"}""", - mapper.writeValueAsString(ClassWithInlineMember(InlineClass("bar"))) + defaultMapper.writeValueAsString(ClassWithInlineMember(InlineClass("bar"))) ) } @@ -29,7 +27,7 @@ class TestGithub356 { fun deserializeValueClass() { assertEquals( ClassWithValueMember(ValueClass("bar")), - mapper.readValue("""{"valueClassProperty":"bar"}""") + defaultMapper.readValue("""{"valueClassProperty":"bar"}""") ) } @@ -37,7 +35,7 @@ class TestGithub356 { fun serializeValueClass() { assertEquals( """{"valueClassProperty":"bar"}""", - mapper.writeValueAsString(ClassWithValueMember(ValueClass("bar"))) + defaultMapper.writeValueAsString(ClassWithValueMember(ValueClass("bar"))) ) } } diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github46.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github46.kt index 9304ff9f5..66a1192b0 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github46.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github46.kt @@ -1,6 +1,6 @@ package com.fasterxml.jackson.module.kotlin.test.github -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.readValue import org.junit.jupiter.api.Test import kotlin.reflect.full.primaryConstructor @@ -10,13 +10,12 @@ class TestGithub46 { @Test fun `map 32 properties`() { // given val json = """{"prop1":true,"prop2":true,"prop3":true,"prop4":true,"prop5":true,"prop6":true,"prop7":true,"prop8":true,"prop9":true,"prop10":true,"prop11":true,"prop12":true,"prop13":true,"prop14":true,"prop15":true,"prop16":true,"prop17":true,"prop18":true,"prop19":true,"prop20":true,"prop21":true,"prop22":true,"prop23":true,"prop24":true,"prop25":true,"prop26":true,"prop27":true,"prop28":true,"prop29":true,"prop30":true,"prop31":true,"prop32":true}""" - val mapper = jacksonObjectMapper() // when - val data: TestData = mapper.readValue(json) + val data: TestData = defaultMapper.readValue(json) assertEquals(TestData(true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true), data) - val rejson = mapper.writeValueAsString(data) + val rejson = defaultMapper.writeValueAsString(data) // then assertEquals(json, rejson) @@ -67,4 +66,4 @@ class TestGithub46 { var prop31: Boolean = false, var prop32: Boolean = false ) -} \ No newline at end of file +} diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github490.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github490.kt index fbba60d7e..403973220 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github490.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github490.kt @@ -2,15 +2,14 @@ package com.fasterxml.jackson.module.kotlin.test.github import com.fasterxml.jackson.databind.JsonNode import com.fasterxml.jackson.databind.node.NullNode -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.readValue import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertNull import org.junit.jupiter.api.Test class TestGithub490 { - val mapper = jacksonObjectMapper() - val value: DataClassWithAllNullableParams = mapper.readValue( + val value: DataClassWithAllNullableParams = defaultMapper.readValue( "{" + "\"jsonNodeValueWithNullAsDefaultProvidedNull\":null, " + "\"jsonNodeValueProvidedNull\":null}" diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github50.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github50.kt index be59d743c..d6098af09 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github50.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github50.kt @@ -1,7 +1,7 @@ package com.fasterxml.jackson.module.kotlin.test.github; import com.fasterxml.jackson.annotation.JsonUnwrapped -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.readValue import org.junit.jupiter.api.Test import kotlin.test.assertEquals @@ -17,7 +17,7 @@ class TestGithub50 { @Test fun testGithub50UnwrappedError() { val json = """{"firstName":"John","lastName":"Smith","position":"Manager"}""" - val obj: Employee = jacksonObjectMapper().readValue(json) + val obj: Employee = defaultMapper.readValue(json) assertEquals(Name("John", "Smith"), obj.name) assertEquals("Manager", obj.position) } diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github52.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github52.kt index ad85d4e7b..81daa3f4c 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github52.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github52.kt @@ -2,13 +2,11 @@ package com.fasterxml.jackson.module.kotlin.test.github import com.fasterxml.jackson.annotation.JsonIgnore import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import org.junit.jupiter.api.Test import kotlin.test.assertEquals class TestGithub52 { - private val mapper = jacksonObjectMapper() - @Test fun testBooleanPropertyInConstructor() { data class BooleanPropertyInConstructor( @@ -16,7 +14,7 @@ class TestGithub52 { val bar: Boolean = true ) - assertEquals("""{"is_bar":true}""", mapper.writeValueAsString(BooleanPropertyInConstructor())) + assertEquals("""{"is_bar":true}""", defaultMapper.writeValueAsString(BooleanPropertyInConstructor())) } @Test @@ -26,7 +24,7 @@ class TestGithub52 { val isBar2: Boolean = true ) - assertEquals("""{"is_bar2":true}""", mapper.writeValueAsString(IsPrefixedBooleanPropertyInConstructor())) + assertEquals("""{"is_bar2":true}""", defaultMapper.writeValueAsString(IsPrefixedBooleanPropertyInConstructor())) } @Test @@ -36,7 +34,7 @@ class TestGithub52 { val lol: String = "sdf" ) - assertEquals("""{"is_lol":"sdf"}""", mapper.writeValueAsString(IsPrefixedStringPropertyInConstructor())) + assertEquals("""{"is_lol":"sdf"}""", defaultMapper.writeValueAsString(IsPrefixedStringPropertyInConstructor())) } @Test @@ -48,7 +46,7 @@ class TestGithub52 { val foo: Boolean = true } - assertEquals("""{"is_foo":true}""", mapper.writeValueAsString(BooleanPropertyInBody())) + assertEquals("""{"is_foo":true}""", defaultMapper.writeValueAsString(BooleanPropertyInBody())) } @Test @@ -60,6 +58,6 @@ class TestGithub52 { val isFoo2: Boolean = true } - assertEquals("""{"is_foo2":true}""", mapper.writeValueAsString(IsPrefixedBooleanPropertyInBody())) + assertEquals("""{"is_foo2":true}""", defaultMapper.writeValueAsString(IsPrefixedBooleanPropertyInBody())) } } diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github526.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github526.kt index 2dfbff641..08a4ead1c 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github526.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github526.kt @@ -2,7 +2,7 @@ package com.fasterxml.jackson.module.kotlin.test.github import com.fasterxml.jackson.annotation.JsonSetter import com.fasterxml.jackson.annotation.Nulls -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.readValue import org.junit.jupiter.api.Test import kotlin.test.assertEquals @@ -12,8 +12,7 @@ class Github526 { @Test fun test() { - val mapper = jacksonObjectMapper() - val d = mapper.readValue("""{"v":null}""") + val d = defaultMapper.readValue("""{"v":null}""") assertEquals(-1, d.v) } diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github56.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github56.kt index b7a35c7ab..6af1547cc 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github56.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github56.kt @@ -2,8 +2,8 @@ package com.fasterxml.jackson.module.kotlin.test.github import com.fasterxml.jackson.annotation.JsonInclude import com.fasterxml.jackson.annotation.JsonUnwrapped -import com.fasterxml.jackson.databind.ObjectMapper -import com.fasterxml.jackson.module.kotlin.* +import com.fasterxml.jackson.module.kotlin.defaultMapper +import com.fasterxml.jackson.module.kotlin.readValue import org.junit.jupiter.api.Test import kotlin.test.assertEquals @@ -36,8 +36,6 @@ private class TestGithub56 { val crops: Map? = null ) - val mapper: ObjectMapper = jacksonObjectMapper() - private val gallery = TestGallery( id = "id", headline = "headline", @@ -54,13 +52,13 @@ private class TestGithub56 { @Test fun serializes() { - val result = mapper.writeValueAsString(TestGalleryWidget_BAD("widgetReferenceId", gallery)) + val result = defaultMapper.writeValueAsString(TestGalleryWidget_BAD("widgetReferenceId", gallery)) assertEquals(validJson, result) } @Test fun deserializesSuccessful() { - val obj = mapper.readValue(validJson) + val obj = defaultMapper.readValue(validJson) assertEquals("widgetReferenceId", obj.widgetReferenceId) assertEquals(gallery, obj.gallery) @@ -68,6 +66,6 @@ private class TestGithub56 { @Test fun deserializesCorrectly() { - mapper.readValue(validJson) + defaultMapper.readValue(validJson) } } diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github62.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github62.kt index 3a3e46623..4aa83ffe7 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github62.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github62.kt @@ -1,6 +1,6 @@ package com.fasterxml.jackson.module.kotlin.test.github -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import org.junit.jupiter.api.Test import kotlin.test.assertEquals @@ -9,10 +9,10 @@ class TestGithub62 { fun testAnonymousClassSerialization() { val externalValue = "ggg" - val result = jacksonObjectMapper().writeValueAsString(object { + val result = defaultMapper.writeValueAsString(object { val value = externalValue }) assertEquals("""{"value":"ggg"}""", result) } -} \ No newline at end of file +} diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github738.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github738.kt index 2104aaafe..668f268d4 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github738.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github738.kt @@ -3,7 +3,7 @@ package com.fasterxml.jackson.module.kotlin.test.github import com.fasterxml.jackson.annotation.JsonSetter import com.fasterxml.jackson.annotation.Nulls import com.fasterxml.jackson.databind.exc.MismatchedInputException -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.readValue import org.junit.jupiter.api.Assertions.assertThrows import org.junit.jupiter.api.Test @@ -13,8 +13,7 @@ class Github738 { @Test fun test() { - val mapper = jacksonObjectMapper() // nulls = FAIL is reflected if it is primitive and missing - assertThrows(MismatchedInputException::class.java) { mapper.readValue("{}") } + assertThrows(MismatchedInputException::class.java) { defaultMapper.readValue("{}") } } } diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github80.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github80.kt index bab26ffff..c35672d05 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github80.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github80.kt @@ -1,36 +1,32 @@ package com.fasterxml.jackson.module.kotlin.test.github import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import org.junit.jupiter.api.Test import kotlin.test.assertEquals class TestGithub80 { @Test fun testIsBool() { - val mapper = jacksonObjectMapper() - val example = IsBoolExample(true) - val json = mapper.writeValueAsString(example) + val json = defaultMapper.writeValueAsString(example) assertEquals("{\"isTrueOrFalse\":true}", json) - val deserialized = mapper.readValue(json, IsBoolExample::class.java) + val deserialized = defaultMapper.readValue(json, IsBoolExample::class.java) assertEquals(example.isTrueOrFalse, deserialized.isTrueOrFalse) } @Test fun testAnnotatedIsBool() { - val mapper = jacksonObjectMapper() - val example = IsBoolAnnotatedExample(true) - val json = mapper.writeValueAsString(example) + val json = defaultMapper.writeValueAsString(example) assertEquals("{\"isTrueOrFalse\":true}", json) - val deserialized = mapper.readValue(json, IsBoolAnnotatedExample::class.java) + val deserialized = defaultMapper.readValue(json, IsBoolAnnotatedExample::class.java) assertEquals(example.isTrue, deserialized.isTrue) } class IsBoolExample(val isTrueOrFalse: Boolean) class IsBoolAnnotatedExample(@JsonProperty("isTrueOrFalse") val isTrue: Boolean) -} \ No newline at end of file +} diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github88.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github88.kt index 2eba29f9d..b5d3e19fe 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github88.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github88.kt @@ -1,6 +1,6 @@ package com.fasterxml.jackson.module.kotlin.test.github -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import org.junit.jupiter.api.Test import kotlin.test.assertEquals @@ -9,14 +9,14 @@ class TestGithub88 { @Test fun shouldDeserializeSuccessfullyKotlinCloneableObject() { - val result = jacksonObjectMapper().writeValueAsString(CloneableKotlinObj("123")) + val result = defaultMapper.writeValueAsString(CloneableKotlinObj("123")) assertEquals("{\"id\":\"123\"}", result) } @Test fun shouldDeserializeSuccessfullyJavaCloneableObject() { - val result = jacksonObjectMapper().writeValueAsString(CloneableJavaObj("123")) + val result = defaultMapper.writeValueAsString(CloneableJavaObj("123")) assertEquals("{\"id\":\"123\"}", result) } diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github91.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github91.kt index 274d2ec39..f6e8a8444 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github91.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github91.kt @@ -2,7 +2,7 @@ package com.fasterxml.jackson.module.kotlin.test.github import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonValue -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.readValue import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test @@ -21,9 +21,8 @@ class TestGithub91 { @Test fun testJsonParsing() { - val mapper = jacksonObjectMapper() - val dataClass1 = mapper.readValue(jsonData) + val dataClass1 = defaultMapper.readValue(jsonData) assertEquals(DataClass1("my name", DataClass2("some value")), dataClass1) - assertEquals("{\"name\":\"my name\",\"content\":\"some value\"}", mapper.writeValueAsString(dataClass1)) + assertEquals("{\"name\":\"my name\",\"content\":\"some value\"}", defaultMapper.writeValueAsString(dataClass1)) } } diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/GithubDatabind1328.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/GithubDatabind1328.kt index 46e49ed0f..2988a681e 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/GithubDatabind1328.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/GithubDatabind1328.kt @@ -3,7 +3,7 @@ package com.fasterxml.jackson.module.kotlin.test.github import com.fasterxml.jackson.annotation.JsonSubTypes import com.fasterxml.jackson.annotation.JsonTypeInfo import com.fasterxml.jackson.annotation.JsonTypeName -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.readValue import org.junit.jupiter.api.Test import kotlin.test.assertEquals @@ -11,8 +11,7 @@ import kotlin.test.assertEquals class TestGithubDatabind1328 { @Test fun testPolymorphicWithEnum() { - val mapper = jacksonObjectMapper() - val invite = mapper.readValue( + val invite = defaultMapper.readValue( """|{ | "kind": "CONTACT", | "to": { @@ -52,4 +51,4 @@ class TestGithubDatabind1328 { CONTACT, USER } -} \ No newline at end of file +} diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/TestCasesFromSlack.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/TestCasesFromSlack.kt index 9ff0c6b69..0b8dba094 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/TestCasesFromSlack.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/TestCasesFromSlack.kt @@ -30,7 +30,7 @@ class TestCasesFromSlack1 { {"host":{"id":"host123","name":"A Czar"},"activity":"Kotlin Programming","invited":[{"id":"Guest1","name":"Mr Kotlin","rsvp": "going"}]} """) - jacksonObjectMapper().readValue(""" + defaultMapper.readValue(""" {"host":{"id":"host123","name":"A Czar"},"activity":"Kotlin Programming","invited":[{"id":"Guest1","name":"Mr Kotlin","rsvp": "going"}]} """) } @@ -56,8 +56,8 @@ class TestCasesFromSlack2 { } @Test fun testCzarSpringThing2() { - jacksonObjectMapper().readValue(""" + defaultMapper.readValue(""" {"host":{"id":"host123","name":"A Czar"},"activity":"Kotlin Programming","invited":[{"id":"Guest1","name":"Mr Kotlin","rsvp": "going"}]} """) } -} \ No newline at end of file +} diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/failing/GitHub451.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/failing/GitHub451.kt index fde983652..78b1f112e 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/failing/GitHub451.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/failing/GitHub451.kt @@ -1,6 +1,6 @@ package com.fasterxml.jackson.module.kotlin.test.github.failing -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertThrows import org.opentest4j.AssertionFailedError @@ -17,14 +17,12 @@ class GitHub451 { fun getGraultGraply(): String = bazQux } - val mapper = jacksonObjectMapper() - @Test fun serializeTest() { val expected = """{"foo-bar":"a","baz-qux":"b","quux-corge":"a","grault-graply":"b"}""" val src = Target("a", "b") - val json = mapper.writeValueAsString(src) + val json = defaultMapper.writeValueAsString(src) assertThrows("GitHub #451 has been fixed!") { assertEquals(expected, json) } diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/failing/Github242.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/failing/Github242.kt index 95eb8bdbe..e47355e45 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/failing/Github242.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/failing/Github242.kt @@ -1,6 +1,6 @@ package com.fasterxml.jackson.module.kotlin.test.github.failing -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.readValue import org.junit.jupiter.api.Test import kotlin.test.assertEquals @@ -9,14 +9,12 @@ import kotlin.test.assertEquals class Github242 { data class IntValue(val value: Int) - private val objectMapper = jacksonObjectMapper() - // Since `nullish` is entered for a `non-null` value, deserialization is expected to fail, // but at the moment the process continues with the default value set on the `databind`. @Test fun `test value throws - Int`(){ - val v0 =objectMapper.readValue("{}") - val v1 =objectMapper.readValue("{\"value\":null}") + val v0 = defaultMapper.readValue("{}") + val v1 = defaultMapper.readValue("{\"value\":null}") assertEquals(0, v0.value) assertEquals(v0, v1) diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/failing/Github271AlphaSortProperties.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/failing/Github271AlphaSortProperties.kt index e0f411b76..60ce4b13b 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/failing/Github271AlphaSortProperties.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/failing/Github271AlphaSortProperties.kt @@ -1,7 +1,7 @@ package com.fasterxml.jackson.module.kotlin.test.github.failing import com.fasterxml.jackson.annotation.JsonPropertyOrder -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.test.expectFailure import org.junit.jupiter.api.Test import kotlin.test.assertEquals @@ -14,9 +14,7 @@ class TestGithub271 { @Test fun testAlphabeticFields() { - val mapper = jacksonObjectMapper() - - val json = mapper.writeValueAsString(Foo("a", "c")) + val json = defaultMapper.writeValueAsString(Foo("a", "c")) expectFailure("GitHub #271 has been fixed!") { assertEquals("""{"a":"a","b":"b","c":"c"}""", json) } diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/failing/Github474.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/failing/Github474.kt index 8d64977fb..f7fa2515c 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/failing/Github474.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/failing/Github474.kt @@ -1,7 +1,7 @@ package com.fasterxml.jackson.module.kotlin.test.github.failing import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.test.expectFailure import org.junit.jupiter.api.Test import kotlin.test.assertEquals @@ -15,7 +15,7 @@ class TestGithub474 { expectFailure("GitHub #474 has been fixed!") { assertEquals( """{"child-prop":"foo","parent-prop":"foo"}""", - jacksonObjectMapper().writeValueAsString(Child("foo")) + defaultMapper.writeValueAsString(Child("foo")) ) } } diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/failing/Github518.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/failing/Github518.kt index 0e662849c..08250d4c1 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/failing/Github518.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/failing/Github518.kt @@ -1,7 +1,7 @@ package com.fasterxml.jackson.module.kotlin.test.github.failing import com.fasterxml.jackson.module.kotlin.KotlinFeature.SingletonSupport -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.jsonMapper import com.fasterxml.jackson.module.kotlin.kotlinModule import com.fasterxml.jackson.module.kotlin.readValue @@ -20,7 +20,7 @@ class TestGithub518 { */ @Test fun deserializeEmptyObjectToSingletonUnit() { - assertSame(jacksonObjectMapper().readValue("{}"), Unit) + assertSame(defaultMapper.readValue("{}"), Unit) } /** @@ -30,7 +30,7 @@ class TestGithub518 { @Test fun deserializeEmptyObjectToSingletonUnitFails() { expectFailure("GitHub #518 has been fixed!") { - assertSame(jacksonObjectMapper().readValue("{}"), Unit) + assertSame(defaultMapper.readValue("{}"), Unit) } } diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/failing/Github54.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/failing/Github54.kt index 78d2f0654..b0958c502 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/failing/Github54.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/failing/Github54.kt @@ -3,7 +3,7 @@ package com.fasterxml.jackson.module.kotlin.test.github.failing import com.fasterxml.jackson.annotation.JsonIdentityInfo import com.fasterxml.jackson.annotation.ObjectIdGenerators import com.fasterxml.jackson.databind.deser.UnresolvedForwardReference -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.readValue import com.fasterxml.jackson.module.kotlin.test.expectFailure import org.junit.jupiter.api.Test @@ -11,8 +11,6 @@ import org.junit.jupiter.api.Test class TestGithub54 { @Test fun testDeserWithIdentityInfo() { - val mapper = jacksonObjectMapper() - val entity1 = Entity1("test_entity1") val entity2 = Entity2("test_entity2", entity1 = entity1) val rootEntity1 = Entity1("root_entity1", entity2 = entity2) @@ -20,9 +18,9 @@ class TestGithub54 { entity1.parent = rootEntity1 entity1.entity2 = entity2 - val json = mapper.writeValueAsString(entity1) + val json = defaultMapper.writeValueAsString(entity1) expectFailure("GitHub #54 has been fixed!") { - mapper.readValue(json) + defaultMapper.readValue(json) } } diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/failing/Github611.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/failing/Github611.kt index f8bb69afd..cd0a307fe 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/failing/Github611.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/failing/Github611.kt @@ -1,7 +1,7 @@ package com.fasterxml.jackson.module.kotlin.test.github.failing import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.readValue import org.junit.jupiter.api.Test import kotlin.test.assertEquals @@ -22,8 +22,7 @@ class TestGithub611 { @Test fun testJsonParsing() { - val mapper = jacksonObjectMapper() - val dataClassInstance = mapper.readValue(jsonData) + val dataClassInstance = defaultMapper.readValue(jsonData) assertEquals(50000.toUShort(), dataClassInstance.id) } } diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/failing/Github71.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/failing/Github71.kt index c1210e300..1932d7523 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/failing/Github71.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/failing/Github71.kt @@ -1,6 +1,6 @@ package com.fasterxml.jackson.module.kotlin.test.github.failing -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.readValue import com.fasterxml.jackson.module.kotlin.test.expectFailure import org.junit.jupiter.api.Test @@ -13,11 +13,11 @@ class TestGithub71 { @Test fun testInternalPropertySerliazation() { - val json = jacksonObjectMapper().writeValueAsString(Identifiable()) + val json = defaultMapper.writeValueAsString(Identifiable()) expectFailure("GitHub #71 has been fixed!") { assertEquals("{\"identity\":null}", json) // fails: {"identity$jackson_module_kotlin":null} - val newInstance = jacksonObjectMapper().readValue(json) + val newInstance = defaultMapper.readValue(json) assertEquals(Identifiable(), newInstance) } } diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/failing/GithubDatabind1329.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/failing/GithubDatabind1329.kt index cac4e097a..62bf1bcd4 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/failing/GithubDatabind1329.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/failing/GithubDatabind1329.kt @@ -3,7 +3,7 @@ package com.fasterxml.jackson.module.kotlin.test.github.failing import com.fasterxml.jackson.annotation.JsonSubTypes import com.fasterxml.jackson.annotation.JsonTypeInfo import com.fasterxml.jackson.annotation.JsonTypeName -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.defaultMapper import com.fasterxml.jackson.module.kotlin.readValue import com.fasterxml.jackson.module.kotlin.test.expectFailure import org.junit.jupiter.api.Test @@ -16,8 +16,7 @@ import kotlin.test.assertNull class GithubDatabind1329 { @Test fun testPolymorphicWithEnum() { - val mapper = jacksonObjectMapper() - val invite = mapper.readValue( + val invite = defaultMapper.readValue( """|{ | "kind": "CONTACT", | "kindForMapper": "CONTACT",