Skip to content

Commit

Permalink
Add value class fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Daeda88 committed Jan 27, 2024
1 parent 59b4522 commit 7a2ae5d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ class FirebaseEncoder(
this.value = value
}

override fun encodeInline(descriptor: SerialDescriptor): Encoder =
FirebaseEncoder(settings)
override fun encodeInline(descriptor: SerialDescriptor): Encoder = this

override fun <T> encodeSerializableValue(serializer: SerializationStrategy<T>, value: T) {
encodePolymorphically(serializer, value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import kotlinx.serialization.builtins.MapSerializer
import kotlinx.serialization.builtins.serializer
import kotlinx.serialization.modules.SerializersModule
import kotlinx.serialization.modules.polymorphic
import kotlin.jvm.JvmInline
import kotlin.test.Test
import kotlin.test.assertEquals

Expand Down Expand Up @@ -55,6 +56,13 @@ data class NestedClass(
val abstractMap: Map<AbstractClass, AbstractClass>
)

@Serializable
@JvmInline
value class ValueClass(val int: Int)

@Serializable
data class ValueClassWrapper(val value: ValueClass)

class EncodersTest {

@Test
Expand Down Expand Up @@ -191,6 +199,28 @@ class EncodersTest {
assertEquals(nestedClass, decoded)
}

@Test
fun encodeDecodeValueClassWrapper() {
val testValueClassWrapper = ValueClassWrapper(ValueClass(42))
val encoded = encode(ValueClassWrapper.serializer(), testValueClassWrapper) { encodeDefaults = false }

nativeAssertEquals(nativeMapOf("value" to 42), encoded)

val decoded = decode(ValueClassWrapper.serializer(), encoded)
assertEquals(testValueClassWrapper, decoded)
}

@Test
fun encodeDecodeValueClass() {
val testValueClass = ValueClass(42)
val encoded = encode(ValueClass.serializer(), testValueClass) { encodeDefaults = false }

nativeAssertEquals(42, encoded)

val decoded = decode(ValueClass.serializer(), encoded)
assertEquals(testValueClass, decoded)
}

@Test
fun reencodeTransformationList() {
val reencoded = reencodeTransformation<List<String>>(nativeListOf("One", "Two", "Three")) {
Expand Down

0 comments on commit 7a2ae5d

Please sign in to comment.