Skip to content

Commit ecf7452

Browse files
committed
Update DelegatingSerializer to require a different serialName
1 parent fe3da8f commit ecf7452

File tree

4 files changed

+26
-13
lines changed

4 files changed

+26
-13
lines changed

Changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Changes:
88
- Tidy up the implementation of the constructors of the
99
`DefaultSerializationPolicy`. This might have slight consequences
1010
in binary compatibility for (experimental) inheritance.
11+
- Change `DelegatingSerializer` (in serialutil) to take the serial
12+
name as parameter as using the delegate is not valid.
1113

1214
Fixes:
1315
- Fix trimming of strings inside a mixed context where there is an

serialutil/api/serialutil.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public abstract class nl/adaptivity/serialutil/DelegateSerializer : kotlinx/seri
1616
}
1717

1818
public abstract class nl/adaptivity/serialutil/DelegatingSerializer : kotlinx/serialization/KSerializer {
19+
public fun <init> (Ljava/lang/String;Lkotlinx/serialization/KSerializer;)V
1920
public fun <init> (Lkotlinx/serialization/KSerializer;)V
2021
public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object;
2122
public abstract fun fromDelegate (Ljava/lang/Object;)Ljava/lang/Object;

serialutil/api/serialutil.klib.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
// Library unique name: <io.github.pdvrieze.xmlutil:serialutil>
99
abstract class <#A: kotlin/Any?, #B: kotlin/Any?> nl.adaptivity.serialutil/DelegatingSerializer : kotlinx.serialization/KSerializer<#A> { // nl.adaptivity.serialutil/DelegatingSerializer|null[0]
10+
constructor <init>(kotlin/String, kotlinx.serialization/KSerializer<#B>) // nl.adaptivity.serialutil/DelegatingSerializer.<init>|<init>(kotlin.String;kotlinx.serialization.KSerializer<1:1>){}[0]
1011
constructor <init>(kotlinx.serialization/KSerializer<#B>) // nl.adaptivity.serialutil/DelegatingSerializer.<init>|<init>(kotlinx.serialization.KSerializer<1:1>){}[0]
1112

1213
final val delegateSerializer // nl.adaptivity.serialutil/DelegatingSerializer.delegateSerializer|{}delegateSerializer[0]

serialutil/src/commonMain/kotlin/nl/adaptivity/serialutil/DelegatingSerializer.kt

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
/*
2-
* Copyright (c) 2021.
2+
* Copyright (c) 2021-2025.
33
*
44
* This file is part of xmlutil.
55
*
6-
* This file is licenced to you under the Apache License, Version 2.0 (the
7-
* "License"); you may not use this file except in compliance
8-
* with the License. You should have received a copy of the license with the source distribution.
9-
* Alternatively, you may obtain a copy of the License at
6+
* This file is licenced to you under the Apache License, Version 2.0
7+
* (the "License"); you may not use this file except in compliance
8+
* with the License. You should have received a copy of the license
9+
* with the source distribution. Alternatively, you may obtain a copy
10+
* of the License at
1011
*
1112
* http://www.apache.org/licenses/LICENSE-2.0
1213
*
13-
* Unless required by applicable law or agreed to in writing,
14-
* software distributed under the License is distributed on an
15-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16-
* KIND, either express or implied. See the License for the
17-
* specific language governing permissions and limitations
18-
* under the License.
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
17+
* implied. See the License for the specific language governing
18+
* permissions and limitations under the License.
1919
*/
2020

2121
package nl.adaptivity.serialutil
@@ -25,7 +25,16 @@ import kotlinx.serialization.descriptors.SerialDescriptor
2525
import kotlinx.serialization.encoding.Decoder
2626
import kotlinx.serialization.encoding.Encoder
2727

28-
abstract class DelegatingSerializer<T, D>(val delegateSerializer: KSerializer<D>): KSerializer<T> {
28+
abstract class DelegatingSerializer<T, D>(
29+
serialName: String,
30+
val delegateSerializer: KSerializer<D>
31+
): KSerializer<T> {
32+
33+
@Deprecated("Use serializer that specifies the serial name")
34+
constructor(delegateSerializer: KSerializer<D>) : this(
35+
delegateSerializer.descriptor.serialName + "_delegate",
36+
delegateSerializer
37+
)
2938

3039
abstract fun fromDelegate(delegate: D): T
3140

@@ -35,7 +44,7 @@ abstract class DelegatingSerializer<T, D>(val delegateSerializer: KSerializer<D>
3544
return fromDelegate(delegateSerializer.deserialize(decoder))
3645
}
3746

38-
override val descriptor: SerialDescriptor get() = delegateSerializer.descriptor
47+
override val descriptor: SerialDescriptor = SerialDescriptor(serialName, delegateSerializer.descriptor)
3948

4049
override fun serialize(encoder: Encoder, value: T) {
4150
delegateSerializer.serialize(encoder, value.toDelegate())

0 commit comments

Comments
 (0)