Skip to content

Commit

Permalink
Another defaults fix
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownJoe796 committed Nov 19, 2024
1 parent 4cf8bde commit 7873efd
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,12 @@ data class VirtualStruct(
}
}
val defaults by lazy {
serializers.map { it.default() }
fields.zip(serializers) { field, serializer ->
field.defaultJson?.let {
return@zip DefaultDecoder.json.decodeFromString(serializer, it)
}
serializer.default()
}
}
val defaultInstance by lazy { VirtualInstance(this, defaults) }
val serializableProperties: Array<SerializableProperty<VirtualInstance, Any?>> by lazy {
Expand All @@ -102,7 +107,9 @@ data class VirtualStruct(
}

override fun deserialize(decoder: Decoder): VirtualInstance {
val values = Array<Any?>(fields.size) { specifiedDefaults[it] }
val values = Array<Any?>(fields.size) {
specifiedDefaults[it].takeUnless { it == DefaultNotPresent }
}
val s = decoder.beginStructure(descriptor)
while (true) {
val index = s.decodeElementIndex(descriptor)
Expand Down

0 comments on commit 7873efd

Please sign in to comment.