Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

URLs don't encode/decode properly #22

Open
nicked opened this issue Feb 4, 2022 · 0 comments · May be fixed by #23
Open

URLs don't encode/decode properly #22

nicked opened this issue Feb 4, 2022 · 0 comments · May be fixed by #23

Comments

@nicked
Copy link

nicked commented Feb 4, 2022

A simple model like this fails to encode and then decode successfully:

struct Link: Codable {
    let url: URL
}

This is because like Date and Data types, URLs also need to be handled as a special case by coders.

Here's how they're handled in the Swift JSONEncoder:
https://github.com/apple/swift-corelibs-foundation/blob/943fee90d095a1708da826e7641636a3cbe9642e/Sources/Foundation/JSONEncoder.swift#L445

If left to encode themselves, URLs create a base/relative URL part, whereas the JSONEncoder just outputs the absoluteString as a normal String field.

@nicked nicked linked a pull request Feb 4, 2022 that will close this issue
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant