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:
- Incorrect DateEncodingStrategy when using Date wrapped in AnyEncodable
- How to encode objects of unknown type?
(among others)