Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IO: Fix LocalPath serializing transient fields for already deleted files in NORMAL mode #899

Merged
merged 1 commit into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ data class LocalPath(
@IgnoredOnParcel override val name: String
get() = file.name

@IgnoredOnParcel internal var segmentsCache: Segments? = null
@IgnoredOnParcel @Transient internal var segmentsCache: Segments? = null

@IgnoredOnParcel
override val segments: Segments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@ class LocalPathTest : BaseTest() {
}

@Test
fun `test direct serialization`() {
fun `direct serialization with transient fields`() {
testFile.tryMkFile()
val original = LocalPath.build(file = testFile)

val adapter = moshi.adapter(LocalPath::class.java)

// segmentsCache needs to be ignored during serialization
println(original.segments.toString())

val json = adapter.toJson(original)
json.toComparableJson() shouldBe """
{
Expand All @@ -44,6 +47,27 @@ class LocalPathTest : BaseTest() {
adapter.fromJson(json) shouldBe original
}

@Test
fun `deserialization needs to respect transient fields`() {
testFile.tryMkFile()
val original = LocalPath.build(file = testFile)

val adapter = moshi.adapter(LocalPath::class.java)

val json = """
{
"file": "${testFile.path}",
"pathType":"LOCAL",
"segmentsCache": [
".",
"testfile"
]
}
""".toComparableJson()

adapter.fromJson(json) shouldBe original
}

@Test
fun `test polymorph serialization`() {
testFile.tryMkFile()
Expand Down