Skip to content

Commit

Permalink
Fix nested encoder container for Codable enums
Browse files Browse the repository at this point in the history
  • Loading branch information
ephemer committed Nov 14, 2022
1 parent b04e85c commit 5cbec25
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Sources/WebWorkerKit/JSValueEncoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,10 @@ private struct JSObjectKeyedEncodingContainer<Key: CodingKey>: KeyedEncodingCont

func nestedContainer<NestedKey>(keyedBy keyType: NestedKey.Type, forKey key: Key) -> KeyedEncodingContainer<NestedKey> where NestedKey: CodingKey
{
let encoder = JSValueEncoderImpl(codingPath: encoder.codingPath)
let container = JSObjectKeyedEncodingContainer<NestedKey>(encoder: encoder)
encoder.value = .object(ObjectConstructor.new())
let nestedEncoder = JSValueEncoderImpl(codingPath: encoder.codingPath)
let container = JSObjectKeyedEncodingContainer<NestedKey>(encoder: nestedEncoder)
nestedEncoder.value = .object(ObjectConstructor.new())
encoder.value[dynamicMember: key.stringValue] = nestedEncoder.value
return KeyedEncodingContainer(container)
}

Expand Down

0 comments on commit 5cbec25

Please sign in to comment.