Flight-School / AnyCodable

Type-erased wrappers for Encodable, Decodable, and Codable values
https://flight.school/books/codable
MIT License
1.27k stars 129 forks source link

Need to support more Codable types and support PropertyList coders #27

Open minacle opened 4 years ago

minacle commented 4 years ago

I've checked some structures presented by Foundation framework, and tested them.

There are JSON coders and _PropertyList coders in Foundation framework, so I tested them on JSONEncoder and PropertyListEncoder using this simple script.

And results are below:


















According to results, AnyCodable doesn't cover some major types, and it doesn't support PropertyList coders completely.

cheungbo-mong commented 3 years ago

I've checked some structures presented by Foundation framework, and tested them.

There are JSON coders and _PropertyList coders in Foundation framework, so I tested them on JSONEncoder and PropertyListEncoder using this simple script.

And results are below:

  • AnyEncodable<Array>

    • [JSON] PASS.
    • [PLIST] PASS.
  • Array

    • [JSON] PASS.
    • [PLIST] PASS.
  • AnyEncodable

    • [JSON] ERROR.
    • [PLIST] ERROR.
  • Calendar

    • [JSON] PASS.
    • [PLIST] PASS.
  • AnyEncodable

    • [JSON] ERROR.
    • [PLIST] ERROR.
  • CharacterSet

    • [JSON] PASS.
    • [PLIST] PASS.
  • AnyEncodable

    • [JSON] ERROR.
    • [PLIST] ERROR.
  • Data

    • [JSON] PASS.
    • [PLIST] PASS.
  • AnyEncodable

    • [JSON] PASS.
    • [PLIST] ERROR.
  • Date

    • [JSON] PASS.
    • [PLIST] ERROR.
  • AnyEncodable

    • [JSON] ERROR.
    • [PLIST] ERROR.
  • DateInterval

    • [JSON] PASS.
    • [PLIST] PASS.
  • AnyEncodable

    • [JSON] PASS.
    • [PLIST] ERROR.
  • NSDecimal

    • [JSON] PASS.
    • [PLIST] PASS.
  • AnyEncodable<Dictionary<String, Int>>

    • [JSON] PASS.
    • [PLIST] PASS.
  • Dictionary<String, Int>

    • [JSON] PASS.
    • [PLIST] PASS.
  • AnyEncodable

    • [JSON] ERROR.
    • [PLIST] ERROR.
  • IndexPath

    • [JSON] PASS.
    • [PLIST] PASS.
  • AnyEncodable

    • [JSON] ERROR.
    • [PLIST] ERROR.
  • IndexSet

    • [JSON] PASS.
    • [PLIST] PASS.
  • AnyEncodable

    • [JSON] ERROR.
    • [PLIST] ERROR.
  • Locale

    • [JSON] PASS.
    • [PLIST] PASS.
  • AnyEncodable<Set>

    • [JSON] ERROR.
    • [PLIST] ERROR.
  • Set

    • [JSON] PASS.
    • [PLIST] PASS.
  • AnyEncodable

    • [JSON] PASS.
    • [PLIST] ERROR.
  • String

    • [JSON] PASS.
    • [PLIST] ERROR.
  • AnyEncodable

    • [JSON] ERROR.
    • [PLIST] ERROR.
  • TimeZone

    • [JSON] PASS.
    • [PLIST] PASS.
  • AnyEncodable

    • [JSON] PASS.
    • [PLIST] PASS.
  • URL

    • [JSON] PASS.
    • [PLIST] PASS.
  • AnyEncodable

    • [JSON] ERROR.
    • [PLIST] ERROR.
  • UUID

    • [JSON] PASS.
    • [PLIST] ERROR.

According to results, AnyCodable doesn't cover some major types, and it doesn't support PropertyList coders completely.

Thanks for you types.

I re-implemented it to support "exact type", which is that types like UInt won't be implicitly coerced.

Already passed the test using the types you mentioned above, except Calendar and Local. Somehow, even after encoding and decoding using JSONEncoder and JSONDecoder, the result is still not equatable. Any there will be a crash if Calendar and Locale are both supported at the same time. Still needs further researches.

You can check it out here.

There are huge changes, so I didn't prepare to pr.😶