diff --git a/redwood-protocol/src/commonMain/kotlin/app/cash/redwood/protocol/protocol.kt b/redwood-protocol/src/commonMain/kotlin/app/cash/redwood/protocol/protocol.kt index 3766e1fdf7..b7d3e761a5 100644 --- a/redwood-protocol/src/commonMain/kotlin/app/cash/redwood/protocol/protocol.kt +++ b/redwood-protocol/src/commonMain/kotlin/app/cash/redwood/protocol/protocol.kt @@ -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, diff --git a/redwood-protocol/src/commonTest/kotlin/app/cash/redwood/protocol/ProtocolTest.kt b/redwood-protocol/src/commonTest/kotlin/app/cash/redwood/protocol/ProtocolTest.kt index 378c0aca5f..c60b3a6f15 100644 --- a/redwood-protocol/src/commonTest/kotlin/app/cash/redwood/protocol/ProtocolTest.kt +++ b/redwood-protocol/src/commonTest/kotlin/app/cash/redwood/protocol/ProtocolTest.kt @@ -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 assertJsonRoundtrip(serializer: KSerializer, model: T, json: String) { assertThat(format.encodeToString(serializer, model)).isEqualTo(json) assertThat(format.decodeFromString(serializer, json)).isEqualTo(model)