Skip to content

Commit f61b269

Browse files
ilya-gdkhalanskyjb
authored andcommitted
Rename serialization surrogate and annotate with PublishedAPI
1 parent ff355de commit f61b269

File tree

7 files changed

+17
-14
lines changed

7 files changed

+17
-14
lines changed

core/jvm/src/Instant.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public actual class Instant internal constructor(
101101
internal actual val MAX: Instant = Instant(jtInstant.MAX)
102102
}
103103

104-
private fun writeReplace(): Any = SerializedValue(SerializedValue.INSTANT_TAG, this)
104+
private fun writeReplace(): Any = Ser(Ser.INSTANT_TAG, this)
105105
}
106106

107107
private fun Instant.atZone(zone: TimeZone): java.time.ZonedDateTime = try {

core/jvm/src/LocalDate.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public actual class LocalDate internal constructor(
9191
@JvmName("toEpochDays")
9292
internal fun toEpochDaysJvm(): Int = value.toEpochDay().clampToInt()
9393

94-
private fun writeReplace(): Any = SerializedValue(SerializedValue.DATE_TAG, this)
94+
private fun writeReplace(): Any = Ser(Ser.DATE_TAG, this)
9595
}
9696

9797
@Deprecated("Use the plus overload with an explicit number of units", ReplaceWith("this.plus(1, unit)"))

core/jvm/src/LocalDateTime.kt

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package kotlinx.datetime
77

88
import kotlinx.datetime.format.*
99
import kotlinx.datetime.internal.removeLeadingZerosFromLongYearFormLocalDateTime
10-
import kotlinx.datetime.internal.SerializedValue
1110
import kotlinx.datetime.serializers.LocalDateTimeIso8601Serializer
1211
import kotlinx.serialization.Serializable
1312
import java.time.DateTimeException
@@ -89,5 +88,5 @@ public actual class LocalDateTime internal constructor(
8988
public actual val ISO: DateTimeFormat<LocalDateTime> = ISO_DATETIME
9089
}
9190

92-
private fun writeReplace(): Any = SerializedValue(SerializedValue.DATE_TIME_TAG, this)
91+
private fun writeReplace(): Any = Ser(Ser.DATE_TIME_TAG, this)
9392
}

core/jvm/src/LocalTime.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,5 @@ public actual class LocalTime internal constructor(
9292

9393
}
9494

95-
private fun writeReplace(): Any = SerializedValue(SerializedValue.TIME_TAG, this)
95+
private fun writeReplace(): Any = Ser(Ser.TIME_TAG, this)
9696
}

core/jvm/src/UtcOffsetJvm.kt

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
package kotlinx.datetime
77

88
import kotlinx.datetime.format.*
9-
import kotlinx.datetime.internal.SerializedValue
109
import kotlinx.datetime.serializers.UtcOffsetSerializer
1110
import kotlinx.serialization.Serializable
1211
import java.time.DateTimeException
@@ -48,7 +47,7 @@ public actual class UtcOffset(
4847
public actual val FOUR_DIGITS: DateTimeFormat<UtcOffset> get() = FOUR_DIGIT_OFFSET
4948
}
5049

51-
private fun writeReplace(): Any = SerializedValue(SerializedValue.UTC_OFFSET_TAG, this)
50+
private fun writeReplace(): Any = Ser(Ser.UTC_OFFSET_TAG, this)
5251
}
5352

5453
@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")

core/jvm/src/internal/SerializedValue.kt renamed to core/jvm/src/internal/Ser.kt

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
44
*/
55

6-
package kotlinx.datetime.internal
6+
@file:Suppress("PackageDirectoryMismatch")
7+
package kotlinx.datetime
78

8-
import kotlinx.datetime.*
99
import java.io.*
1010

11-
internal class SerializedValue(var typeTag: Int, var value: Any?) : Externalizable {
11+
@PublishedApi // changing the class name would result in serialization incompatibility
12+
internal class Ser(private var typeTag: Int, private var value: Any?) : Externalizable {
1213
constructor() : this(0, null)
1314

1415
override fun writeExternal(out: ObjectOutput) {

core/jvm/test/JvmSerializationTest.kt

+8-4
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,16 @@ class JvmSerializationTest {
7979

8080
@OptIn(ExperimentalStdlibApi::class)
8181
private fun expectedDeserialization(expected: Any, blockData: String) {
82-
val serialized = "aced0005737200296b6f746c696e782e6461746574696d652e696e7465726e616c2e53657269616c697a656456616c756500000000000000000c0000787077${blockData}78"
82+
val serialized = "aced0005737200146b6f746c696e782e6461746574696d652e53657200000000000000000c0000787077${blockData}78"
8383
val hexFormat = HexFormat { bytes.byteSeparator = "" }
8484

85-
val deserialized = deserialize(serialized.hexToByteArray(hexFormat))
86-
if (expected != deserialized) {
87-
assertEquals(expected, deserialized, "Golden serial form: $serialized\nActual serial form: ${serialize(expected).toHexString(hexFormat)}")
85+
try {
86+
val deserialized = deserialize(serialized.hexToByteArray(hexFormat))
87+
if (expected != deserialized) {
88+
assertEquals(expected, deserialized, "Golden serial form: $serialized\nActual serial form: ${serialize(expected).toHexString(hexFormat)}")
89+
}
90+
} catch (e: Throwable) {
91+
fail("Failed to deserialize $serialized\nActual serial form: ${serialize(expected).toHexString(hexFormat)}", e)
8892
}
8993
}
9094

0 commit comments

Comments
 (0)