Skip to content

Commit

Permalink
Add fallback for property change widget tag (#2369)
Browse files Browse the repository at this point in the history
We don't require this on the host-side yet, so allow deserialization of models from old guests for now.
  • Loading branch information
JakeWharton authored Oct 4, 2024
1 parent 84927a6 commit 20753ed
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public class PropertyChange private constructor(
@SerialName("id")
private val _id: Int,
@SerialName("widget")
private val _widgetTag: Int,
private val _widgetTag: Int = -1,
@SerialName("tag")
private val _tag: Int,
public val value: JsonElement = JsonNull,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ class ProtocolTest {
assertThat(three).hasMessage("ModifierElement array may only have 1 or 2 values. Found: 3")
}

@Test fun propertyChangeMissingWidgetTag() {
val expected = PropertyChange(Id(1), WidgetTag(-1), PropertyTag(2), JsonPrimitive("hello"))
val json = """["property",{"id":1,"tag":2,"value":"hello"}]"""
assertThat(format.decodeFromString(Change.serializer(), json)).isEqualTo(expected)
}

private fun <T> assertJsonRoundtrip(serializer: KSerializer<T>, model: T, json: String) {
assertThat(format.encodeToString(serializer, model)).isEqualTo(json)
assertThat(format.decodeFromString(serializer, json)).isEqualTo(model)
Expand Down

0 comments on commit 20753ed

Please sign in to comment.