Encodable incorrect Json string with URL and Decimal existentials

This isn't a bug, but expected behavior because of how AnyEncodable encodes the underlying value; specifically, because the contents of encodable are being encoded directly into the Encoder, the Encoder never sees the outer type, and can't intercept with strategies that apply in those instances.

e.g., when encodable is a URL, this is calling URL.encode(to: encoder) directly, and control passes to URL's method; the encoder itself never sees URL, so it can't apply its encoding strategy.

There are a few prior threads on the forums here that go into more detail:

(among others)

1 Like