Skip to content

Commit 68525e2

Browse files
authored
Changes wrt databind/#3043: rename SerializerProvider as SerializationContext (#862)
1 parent 70b497c commit 68525e2

File tree

8 files changed

+35
-35
lines changed

8 files changed

+35
-35
lines changed

src/main/kotlin/tools/jackson/module/kotlin/KotlinKeySerializers.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,25 @@ import tools.jackson.core.JsonGenerator
66
import tools.jackson.databind.BeanDescription
77
import tools.jackson.databind.JavaType
88
import tools.jackson.databind.SerializationConfig
9-
import tools.jackson.databind.SerializerProvider
9+
import tools.jackson.databind.SerializationContext
1010
import tools.jackson.databind.ValueSerializer
1111
import tools.jackson.databind.ser.Serializers
1212
import tools.jackson.databind.ser.std.StdSerializer
1313
import java.lang.reflect.Method
1414
import java.lang.reflect.Modifier
1515

1616
internal object ValueClassUnboxKeySerializer : StdSerializer<Any>(Any::class.java) {
17-
override fun serialize(value: Any, gen: JsonGenerator, provider: SerializerProvider) {
17+
override fun serialize(value: Any, gen: JsonGenerator, ctxt: SerializationContext) {
1818
val method = value::class.java.getMethod("unbox-impl")
1919
val unboxed = method.invoke(value)
2020

2121
if (unboxed == null) {
22-
val javaType = provider.typeFactory.constructType(method.genericReturnType)
23-
provider.findNullKeySerializer(javaType, null).serialize(null, gen, provider)
22+
val javaType = ctxt.typeFactory.constructType(method.genericReturnType)
23+
ctxt.findNullKeySerializer(javaType, null).serialize(null, gen, ctxt)
2424
return
2525
}
2626

27-
provider.findKeySerializer(unboxed::class.java, null).serialize(unboxed, gen, provider)
27+
ctxt.findKeySerializer(unboxed::class.java, null).serialize(unboxed, gen, ctxt)
2828
}
2929
}
3030

@@ -40,15 +40,15 @@ internal class ValueClassStaticJsonKeySerializer<T>(
4040
private val keyType: Class<*> = staticJsonKeyGetter.returnType
4141
private val unboxMethod: Method = t.getMethod("unbox-impl")
4242

43-
override fun serialize(value: T, gen: JsonGenerator, provider: SerializerProvider) {
43+
override fun serialize(value: T, gen: JsonGenerator, ctxt: SerializationContext) {
4444
val unboxed = unboxMethod.invoke(value)
4545
val jsonKey: Any? = staticJsonKeyGetter.invoke(null, unboxed)
4646

4747
val serializer = jsonKey
48-
?.let { provider.findKeySerializer(keyType, null) }
49-
?: provider.findNullKeySerializer(provider.constructType(keyType), null)
48+
?.let { ctxt.findKeySerializer(keyType, null) }
49+
?: ctxt.findNullKeySerializer(ctxt.constructType(keyType), null)
5050

51-
serializer.serialize(jsonKey, gen, provider)
51+
serializer.serialize(jsonKey, gen, ctxt)
5252
}
5353

5454
companion object {

src/main/kotlin/tools/jackson/module/kotlin/KotlinSerializers.kt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import tools.jackson.core.JsonGenerator
66
import tools.jackson.databind.BeanDescription
77
import tools.jackson.databind.JavaType
88
import tools.jackson.databind.SerializationConfig
9-
import tools.jackson.databind.SerializerProvider
9+
import tools.jackson.databind.SerializationContext
1010
import tools.jackson.databind.ValueSerializer
1111
import tools.jackson.databind.ser.Serializers
1212
import tools.jackson.databind.ser.std.StdSerializer
@@ -15,25 +15,25 @@ import java.lang.reflect.Modifier
1515
import java.math.BigInteger
1616

1717
object UByteSerializer : StdSerializer<UByte>(UByte::class.java) {
18-
override fun serialize(value: UByte, gen: JsonGenerator, provider: SerializerProvider) {
18+
override fun serialize(value: UByte, gen: JsonGenerator, ctxt: SerializationContext) {
1919
gen.writeNumber(value.toShort())
2020
}
2121
}
2222

2323
object UShortSerializer : StdSerializer<UShort>(UShort::class.java) {
24-
override fun serialize(value: UShort, gen: JsonGenerator, provider: SerializerProvider) {
24+
override fun serialize(value: UShort, gen: JsonGenerator, ctxt: SerializationContext) {
2525
gen.writeNumber(value.toInt())
2626
}
2727
}
2828

2929
object UIntSerializer : StdSerializer<UInt>(UInt::class.java) {
30-
override fun serialize(value: UInt, gen: JsonGenerator, provider: SerializerProvider) {
30+
override fun serialize(value: UInt, gen: JsonGenerator, ctxt: SerializationContext) {
3131
gen.writeNumber(value.toLong())
3232
}
3333
}
3434

3535
object ULongSerializer : StdSerializer<ULong>(ULong::class.java) {
36-
override fun serialize(value: ULong, gen: JsonGenerator, provider: SerializerProvider) {
36+
override fun serialize(value: ULong, gen: JsonGenerator, ctxt: SerializationContext) {
3737
val longValue = value.toLong()
3838
when {
3939
longValue >= 0 -> gen.writeNumber(longValue)
@@ -48,15 +48,15 @@ private fun Class<*>.getStaticJsonValueGetter(): Method? = this.declaredMethods.
4848
}
4949

5050
object ValueClassUnboxSerializer : StdSerializer<Any>(Any::class.java) {
51-
override fun serialize(value: Any, gen: JsonGenerator, provider: SerializerProvider) {
51+
override fun serialize(value: Any, gen: JsonGenerator, ctxt: SerializationContext) {
5252
val unboxed = value::class.java.getMethod("unbox-impl").invoke(value)
5353

5454
if (unboxed == null) {
55-
provider.findNullValueSerializer(null).serialize(null, gen, provider)
55+
ctxt.findNullValueSerializer(null).serialize(null, gen, ctxt)
5656
return
5757
}
5858

59-
provider.findValueSerializer(unboxed::class.java).serialize(unboxed, gen, provider)
59+
ctxt.findValueSerializer(unboxed::class.java).serialize(unboxed, gen, ctxt)
6060
}
6161
}
6262

@@ -66,13 +66,13 @@ internal sealed class ValueClassSerializer<T : Any>(t: Class<T>) : StdSerializer
6666
) : ValueClassSerializer<T>(t) {
6767
private val unboxMethod: Method = t.getMethod("unbox-impl")
6868

69-
override fun serialize(value: T, gen: JsonGenerator, provider: SerializerProvider) {
69+
override fun serialize(value: T, gen: JsonGenerator, ctxt: SerializationContext) {
7070
val unboxed = unboxMethod.invoke(value)
7171
// As shown in the processing of the factory function, jsonValueGetter is always a static method.
7272
val jsonValue: Any? = staticJsonValueGetter.invoke(null, unboxed)
7373
jsonValue
74-
?.let { provider.findValueSerializer(it::class.java).serialize(it, gen, provider) }
75-
?: provider.findNullValueSerializer(null).serialize(null, gen, provider)
74+
?.let { ctxt.findValueSerializer(it::class.java).serialize(it, gen, ctxt) }
75+
?: ctxt.findNullValueSerializer(null).serialize(null, gen, ctxt)
7676
}
7777
}
7878

src/test/kotlin/tools/jackson/module/kotlin/test/KClassSerializerDeserializerTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package tools.jackson.module.kotlin.test
33
import tools.jackson.core.JsonGenerator
44
import tools.jackson.core.JsonParser
55
import tools.jackson.databind.DeserializationContext
6-
import tools.jackson.databind.SerializerProvider
6+
import tools.jackson.databind.SerializationContext
77
import tools.jackson.databind.ValueDeserializer
88
import tools.jackson.databind.ValueSerializer
99
import tools.jackson.databind.module.SimpleModule
@@ -51,7 +51,7 @@ data class TestDoubleData(
5151
)
5252

5353
class RoundingSerializer : ValueSerializer<Double>() {
54-
override fun serialize(value: Double?, gen: JsonGenerator?, serializers: SerializerProvider?) {
54+
override fun serialize(value: Double?, gen: JsonGenerator?, ctxt: SerializationContext?) {
5555
value?.let {
5656
gen?.writeNumber(BigDecimal(it).setScale(2, RoundingMode.HALF_UP))
5757
}

src/test/kotlin/tools/jackson/module/kotlin/test/PropertyRequirednessTests.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ class TestPropertyRequiredness {
192192
}
193193

194194
private fun introspectSerialization(type: Class<*>, mapper: ObjectMapper): BeanDescription =
195-
mapper._serializerProvider().introspectBeanDescription(mapper.constructType(type))
195+
mapper._serializationContext().introspectBeanDescription(mapper.constructType(type))
196196

197197
private fun introspectDeserialization(type: Class<*>, mapper: ObjectMapper): BeanDescription =
198198
mapper._deserializationContext().introspectBeanDescription(mapper.constructType(type))

src/test/kotlin/tools/jackson/module/kotlin/test/SequenceSerdesTests.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import org.junit.Test
44
import tools.jackson.module.kotlin.jacksonObjectMapper
55
import tools.jackson.module.kotlin.readValue
66
import tools.jackson.core.JsonGenerator
7-
import tools.jackson.databind.SerializerProvider
7+
import tools.jackson.databind.SerializationContext
88
import tools.jackson.databind.annotation.JsonSerialize
99
import tools.jackson.databind.ser.std.StdSerializer
1010
import kotlin.test.assertEquals
@@ -47,8 +47,8 @@ class TestSequenceDeserializer {
4747
}
4848

4949
class ContentSer : StdSerializer<String>(String::class.java) {
50-
override fun serialize(value: String, gen: JsonGenerator, provider: SerializerProvider) {
51-
provider.writeValue(gen, "$value-ser")
50+
override fun serialize(value: String, gen: JsonGenerator, ctxt: SerializationContext) {
51+
ctxt.writeValue(gen, "$value-ser")
5252
}
5353
}
5454

src/test/kotlin/tools/jackson/module/kotlin/test/github/GitHub524.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package tools.jackson.module.kotlin.test.github
22

33
import tools.jackson.core.JsonGenerator
4-
import tools.jackson.databind.SerializerProvider
4+
import tools.jackson.databind.SerializationContext
55
import tools.jackson.databind.annotation.JsonSerialize
66
import tools.jackson.databind.module.SimpleModule
77
import tools.jackson.databind.ser.std.StdSerializer
@@ -17,7 +17,7 @@ class GitHub524 {
1717
@JvmInline
1818
value class HasSerializer(val value: Int?)
1919
class Serializer : StdSerializer<HasSerializer>(HasSerializer::class.java) {
20-
override fun serialize(value: HasSerializer, gen: JsonGenerator, provider: SerializerProvider) {
20+
override fun serialize(value: HasSerializer, gen: JsonGenerator, ctxt: SerializationContext) {
2121
gen.writeString(value.toString())
2222
}
2323
}

src/test/kotlin/tools/jackson/module/kotlin/test/github/GitHub618.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package tools.jackson.module.kotlin.test.github
22

33
import org.junit.Test
44
import tools.jackson.core.JsonGenerator
5-
import tools.jackson.databind.SerializerProvider
5+
import tools.jackson.databind.SerializationContext
66
import tools.jackson.databind.annotation.JsonSerialize
77
import tools.jackson.databind.ser.std.StdSerializer
88
import tools.jackson.module.kotlin.jacksonObjectMapper
@@ -13,7 +13,7 @@ class GitHub618 {
1313
@JvmInline
1414
value class V(val value: String) {
1515
class Serializer : StdSerializer<V>(V::class.java) {
16-
override fun serialize(p0: V, p1: JsonGenerator, p2: SerializerProvider) {
16+
override fun serialize(p0: V, p1: JsonGenerator, p2: SerializationContext) {
1717
p1.writeString(p0.toString())
1818
}
1919
}

src/test/kotlin/tools/jackson/module/kotlin/test/github/Github464.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package tools.jackson.module.kotlin.test.github
33
import tools.jackson.core.JsonGenerator
44
import tools.jackson.databind.ObjectMapper
55
import tools.jackson.databind.ObjectWriter
6-
import tools.jackson.databind.SerializerProvider
6+
import tools.jackson.databind.SerializationContext
77
import tools.jackson.databind.json.JsonMapper
88
import tools.jackson.databind.module.SimpleModule
99
import tools.jackson.databind.ser.std.StdSerializer
@@ -17,7 +17,7 @@ import kotlin.test.assertEquals
1717
class Github464 {
1818
class UnboxTest {
1919
object NullValueClassKeySerializer : StdSerializer<ValueClass>(ValueClass::class.java) {
20-
override fun serialize(value: ValueClass?, gen: JsonGenerator, provider: SerializerProvider) {
20+
override fun serialize(value: ValueClass?, gen: JsonGenerator, ctxt: SerializationContext) {
2121
gen.writeName("null-key")
2222
}
2323
}
@@ -107,7 +107,7 @@ class Github464 {
107107
}
108108

109109
object NullValueSerializer : StdSerializer<Any>(Any::class.java) {
110-
override fun serialize(value: Any?, gen: JsonGenerator, provider: SerializerProvider) {
110+
override fun serialize(value: Any?, gen: JsonGenerator, ctxt: SerializationContext) {
111111
gen.writeString("null-value")
112112
}
113113
}
@@ -156,13 +156,13 @@ class Github464 {
156156
value class ValueBySerializer(val value: Int)
157157

158158
object Serializer : StdSerializer<ValueBySerializer>(ValueBySerializer::class.java) {
159-
override fun serialize(value: ValueBySerializer, gen: JsonGenerator, provider: SerializerProvider) {
159+
override fun serialize(value: ValueBySerializer, gen: JsonGenerator, ctxt: SerializationContext) {
160160
gen.writeString(value.value.toString())
161161
}
162162
}
163163

164164
object KeySerializer : StdSerializer<ValueBySerializer>(ValueBySerializer::class.java) {
165-
override fun serialize(value: ValueBySerializer, gen: JsonGenerator, provider: SerializerProvider) {
165+
override fun serialize(value: ValueBySerializer, gen: JsonGenerator, ctxt: SerializationContext) {
166166
gen.writeName(value.value.toString())
167167
}
168168
}

0 commit comments

Comments
 (0)