I think I found an edge case bug of the JSONEncoder and the PListEncoder in Swift Standard Library
I have a model for an API of our service which will return a JSON data in a specific format. I'm trying to design a Swift model to conform to the Swift API Design guideline. In order to achieve that, we want to flatten the properties up to the type. We can use the nestedKey variant for that. However since we have some specific properties based on the type of the data, we decide to have another type for holding those information. The bug is that we need to call nestedKey variant on the same key but for 2 Coding Keys types while encoding the type, the second container will always replace the data encoding by the first container. I believe that it's due to This line of code where the JSONEncoder will create a new container when the nestedKeys method is called.
However the decoding works correctly
We want to convert the above JSON data to be something like this
I think we should fix the Encoders logic not to replace the value encoded by the prior container, this will match with the behavior of the Decoder