diff --git a/Sources/XMLCoder/Decoder/XMLKeyedDecodingContainer.swift b/Sources/XMLCoder/Decoder/XMLKeyedDecodingContainer.swift index f16e09dd..dc7d7c5d 100644 --- a/Sources/XMLCoder/Decoder/XMLKeyedDecodingContainer.swift +++ b/Sources/XMLCoder/Decoder/XMLKeyedDecodingContainer.swift @@ -235,37 +235,19 @@ extension XMLKeyedDecodingContainer { ) } - let elements = container - .withShared { keyedBox -> [KeyedBox.Element] in - if ["value", ""].contains(key.stringValue) { - let keyString = key.stringValue.isEmpty ? "value" : key.stringValue - let value = keyedBox.elements[keyString] - if !value.isEmpty { - return value.map { - if let singleKeyed = $0 as? SingleKeyedBox { - return singleKeyed.element - } else { - return $0 - } - } - } else if let value = keyedBox.value { - return [value] - } else { - return [] - } - } else { - #warning("TODO: just return keyedBox.elements[key.stringValue]") - return keyedBox.elements[key.stringValue].map { - if let singleKeyed = $0 as? SingleKeyedBox { - #warning("Don't get rid of key info just yet!") - // return singleKeyed.element - return singleKeyed - } else { - return $0 - } - } - } + let elements = container.withShared { keyedBox -> [KeyedBox.Element] in + // Handle the coding key value intrinsic case + if ["value", ""].contains(key.stringValue) { + // For each boxed-up element we have, peer in to see if it is a `SingleKeyedBox`. + // A `SingleKeyedBox` bundles an `element` along with its `key` in order to defer + // its evaluation. This is used here in order to prevent the wiping away of + // `NullBox` elements prematurely which may be an empty `String` value in disguise. + // If we have a `SingledKeyedBox` here, extract its element. Otherwise, return the + // boxed-up element as-is. + return keyedBox.elements["value"].map { ($0 as? SingleKeyedBox)?.element ?? $0 } } + return keyedBox.elements[key.stringValue] + } let attributes = container.withShared { keyedBox in keyedBox.attributes[key.stringValue]