-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1740f08
commit 7475731
Showing
11 changed files
with
89 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
plugins { | ||
kotlin("multiplatform") | ||
kotlin("plugin.serialization") | ||
id("com.vanniktech.maven.publish") | ||
} | ||
|
||
applyBasicSetup() | ||
|
||
darwinTargetsFramework() | ||
|
||
kotlin { | ||
sourceSets { | ||
commonMain { | ||
dependencies { | ||
api(project(":core")) | ||
implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:1.6.3") | ||
} | ||
} | ||
|
||
commonTest { | ||
dependencies { | ||
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3") | ||
} | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
serialization/common/src/dev/programadorthi/state/serialization/ValueManagerSerializable.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package dev.programadorthi.state.serialization | ||
|
||
import dev.programadorthi.state.core.ValueManager | ||
import kotlinx.serialization.Serializable | ||
|
||
public typealias ValueManager<T> = @Serializable(with = ValueManagerSerializer::class) ValueManager<T> |
2 changes: 1 addition & 1 deletion
2
...e/serialization/ValueManagerSerializer.kt → ...e/serialization/ValueManagerSerializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...hi/state/core/SerializableValueManager.kt → ...serialization/SerializableValueManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...zation/common/test/dev/programadorthi/state/serialization/SerializableValueManagerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package dev.programadorthi.state.serialization | ||
|
||
import dev.programadorthi.state.core.extension.basicValueManager | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
import kotlinx.serialization.encodeToString | ||
import kotlinx.serialization.json.Json | ||
|
||
internal class SerializableValueManagerTest { | ||
|
||
@Test | ||
fun shouldSerializeAndDeserialize() { | ||
val data = SerializableValueManager( | ||
intValue = basicValueManager(1), | ||
stringValue = basicValueManager("valueManager"), | ||
color = basicValueManager(Color("red")), | ||
composite = basicValueManager( | ||
basicValueManager(listOf(Color("blue"), Color("green"))) | ||
) | ||
) | ||
val json = Json.encodeToString(data) | ||
val decoded = Json.decodeFromString<SerializableValueManager>(json) | ||
|
||
assertEquals( | ||
"""{"intValue":1,"stringValue":"valueManager","color":{"name":"red"},"composite":[{"name":"blue"},{"name":"green"}]}""", | ||
json | ||
) | ||
assertEquals(data, decoded) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
POM_NAME=Serialization | ||
POM_ARTIFACT_ID=serialization |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters