You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
val encoded = encode(ValueClass.serializer(), testValueClass) { encodeDefaults =false }
106
+
107
+
nativeAssertEquals(42, encoded)
108
+
109
+
val decoded = decode(ValueClass.serializer(), encoded)
110
+
assertEquals(testValueClass, decoded)
111
+
}
112
+
99
113
@Test
100
114
funencodeDecodeClass() {
101
-
val testDataClass =TestData(mapOf("key" to "value"), mapOf(1 to 1), true)
115
+
val testDataClass =TestData(mapOf("key" to "value"), mapOf(1 to 1), true, null, ValueClass(42))
102
116
val encoded = encode(TestData.serializer(), testDataClass) { encodeDefaults =false }
103
117
104
-
nativeAssertEquals(nativeMapOf("map" to nativeMapOf("key" to "value"), "otherMap" to nativeMapOf(1 to 1), "bool" to true), encoded)
118
+
nativeAssertEquals(nativeMapOf("map" to nativeMapOf("key" to "value"), "otherMap" to nativeMapOf(1 to 1), "bool" to true, "valueClass" to 42), encoded)
105
119
106
120
val decoded = decode(TestData.serializer(), encoded)
107
121
assertEquals(testDataClass, decoded)
108
122
}
109
123
110
124
@Test
111
125
funencodeDecodeClassNullableValue() {
112
-
val testDataClass =TestData(mapOf("key" to "value"), mapOf(1 to 1), true, nullableBool =true)
126
+
val testDataClass =TestData(mapOf("key" to "value"), mapOf(1 to 1), true, nullableBool =true, ValueClass(42))
113
127
val encoded = encode(TestData.serializer(), testDataClass) { encodeDefaults =true }
114
128
115
-
nativeAssertEquals(nativeMapOf("map" to nativeMapOf("key" to "value"), "otherMap" to nativeMapOf(1 to 1), "bool" to true, "nullableBool" to true), encoded)
129
+
nativeAssertEquals(nativeMapOf("map" to nativeMapOf("key" to "value"), "otherMap" to nativeMapOf(1 to 1), "bool" to true, "nullableBool" to true, "valueClass" to 42), encoded)
116
130
117
131
val decoded = decode(TestData.serializer(), encoded)
118
132
assertEquals(testDataClass, decoded)
119
133
}
120
134
121
135
@Test
122
136
funencodeDecodeGenericClass() {
123
-
val innerClass =TestData(mapOf("key" to "value"), mapOf(1 to 1), true)
137
+
val innerClass =TestData(mapOf("key" to "value"), mapOf(1 to 1), true, valueClass =ValueClass(42))
124
138
val genericClass =GenericClass(innerClass)
125
139
val encoded = encode(GenericClass.serializer(TestData.serializer()), genericClass) { encodeDefaults =true }
126
140
127
-
nativeAssertEquals(nativeMapOf("inner" to nativeMapOf("map" to nativeMapOf("key" to "value"), "otherMap" to nativeMapOf(1 to 1), "bool" to true, "nullableBool" to null)), encoded)
141
+
nativeAssertEquals(nativeMapOf("inner" to nativeMapOf("map" to nativeMapOf("key" to "value"), "otherMap" to nativeMapOf(1 to 1), "bool" to true, "nullableBool" to null, "valueClass" to 42)), encoded)
128
142
129
143
val decoded = decode(GenericClass.serializer(TestData.serializer()), encoded)
130
144
assertEquals(genericClass, decoded)
@@ -199,28 +213,6 @@ class EncodersTest {
199
213
assertEquals(nestedClass, decoded)
200
214
}
201
215
202
-
@Test
203
-
funencodeDecodeValueClassWrapper() {
204
-
val testValueClassWrapper =ValueClassWrapper(ValueClass(42))
205
-
val encoded = encode(ValueClassWrapper.serializer(), testValueClassWrapper) { encodeDefaults =false }
206
-
207
-
nativeAssertEquals(nativeMapOf("value" to 42), encoded)
208
-
209
-
val decoded = decode(ValueClassWrapper.serializer(), encoded)
210
-
assertEquals(testValueClassWrapper, decoded)
211
-
}
212
-
213
-
@Test
214
-
funencodeDecodeValueClass() {
215
-
val testValueClass =ValueClass(42)
216
-
val encoded = encode(ValueClass.serializer(), testValueClass) { encodeDefaults =false }
217
-
218
-
nativeAssertEquals(42, encoded)
219
-
220
-
val decoded = decode(ValueClass.serializer(), encoded)
221
-
assertEquals(testValueClass, decoded)
222
-
}
223
-
224
216
@Test
225
217
funreencodeTransformationList() {
226
218
val reencoded = reencodeTransformation<List<String>>(nativeListOf("One", "Two", "Three")) {
@@ -249,26 +241,39 @@ class EncodersTest {
249
241
nativeAssertEquals(nativeMapOf(), reencoded)
250
242
}
251
243
244
+
@Test
245
+
funreencodeTransformationValueClass() {
246
+
val reencoded = reencodeTransformation<ValueClass>(
247
+
42,
248
+
{ encodeDefaults =false }
249
+
) {
250
+
assertEquals(ValueClass(42), it)
251
+
ValueClass(23)
252
+
}
253
+
254
+
nativeAssertEquals(23, reencoded)
255
+
}
256
+
252
257
@Test
253
258
funreencodeTransformationClass() {
254
259
val reencoded = reencodeTransformation<TestData>(
255
-
nativeMapOf("map" to nativeMapOf("key" to "value"), "otherMap" to nativeMapOf(1 to 1), "bool" to true, "nullableBool" to true),
260
+
nativeMapOf("map" to nativeMapOf("key" to "value"), "otherMap" to nativeMapOf(1 to 1), "bool" to true, "nullableBool" to true, "valueClass" to 42),
256
261
{ encodeDefaults =false }
257
262
) {
258
-
assertEquals(TestData(mapOf("key" to "value"), mapOf(1 to 1), bool =true, nullableBool =true), it)
263
+
assertEquals(TestData(mapOf("key" to "value"), mapOf(1 to 1), bool =true, nullableBool =true, ValueClass(42)), it)
259
264
it.copy(map =mapOf("newKey" to "newValue"), nullableBool =null)
260
265
}
261
266
262
-
nativeAssertEquals(nativeMapOf("map" to nativeMapOf("newKey" to "newValue"), "otherMap" to nativeMapOf(1 to 1), "bool" to true), reencoded)
267
+
nativeAssertEquals(nativeMapOf("map" to nativeMapOf("newKey" to "newValue"), "otherMap" to nativeMapOf(1 to 1), "bool" to true, "valueClass" to 42), reencoded)
263
268
}
264
269
265
270
@Test
266
271
funreencodeTransformationNullableValue() {
267
272
val reencoded = reencodeTransformation<TestData?>(
268
-
nativeMapOf("map" to nativeMapOf("key" to "value"), "otherMap" to nativeMapOf(1 to 1), "bool" to true, "nullableBool" to true),
273
+
nativeMapOf("map" to nativeMapOf("key" to "value"), "otherMap" to nativeMapOf(1 to 1), "bool" to true, "nullableBool" to true, "valueClass" to 42),
269
274
{ encodeDefaults =false }
270
275
) {
271
-
assertEquals(TestData(mapOf("key" to "value"), mapOf(1 to 1), bool =true, nullableBool =true), it)
276
+
assertEquals(TestData(mapOf("key" to "value"), mapOf(1 to 1), bool =true, nullableBool =true, valueClass =ValueClass(42)), it)
272
277
null
273
278
}
274
279
@@ -279,17 +284,17 @@ class EncodersTest {
279
284
funreencodeTransformationGenericClass() {
280
285
val reencoded = reencodeTransformation(
281
286
GenericClass.serializer(TestData.serializer()),
282
-
nativeMapOf("inner" to nativeMapOf("map" to nativeMapOf("key" to "value"), "otherMap" to nativeMapOf(1 to 1), "bool" to true, "nullableBool" to false)),
287
+
nativeMapOf("inner" to nativeMapOf("map" to nativeMapOf("key" to "value"), "otherMap" to nativeMapOf(1 to 1), "bool" to true, "nullableBool" to false, "valueClass" to 42)),
283
288
{ encodeDefaults =false }
284
289
) {
285
290
assertEquals(
286
-
GenericClass(TestData(mapOf("key" to "value"), mapOf(1 to 1), bool =true, nullableBool =false)),
291
+
GenericClass(TestData(mapOf("key" to "value"), mapOf(1 to 1), bool =true, nullableBool =false, valueClass =ValueClass(42))),
287
292
it
288
293
)
289
294
GenericClass(it.inner.copy(map =mapOf("newKey" to "newValue"), nullableBool =null))
290
295
}
291
296
292
-
nativeAssertEquals(nativeMapOf("inner" to nativeMapOf("map" to nativeMapOf("newKey" to "newValue"), "otherMap" to nativeMapOf(1 to 1), "bool" to true)), reencoded)
297
+
nativeAssertEquals(nativeMapOf("inner" to nativeMapOf("map" to nativeMapOf("newKey" to "newValue"), "otherMap" to nativeMapOf(1 to 1), "bool" to true, "valueClass" to 42)), reencoded)
0 commit comments