Flight-School / AnyCodable

Type-erased wrappers for Encodable, Decodable, and Codable values

Home Page:https://flight.school/books/codable

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Need to support more Codable types and support PropertyList coders

minacle opened this issue · comments

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<Int>>

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

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

  • AnyEncodable<Calendar>

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

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

  • AnyEncodable<CharacterSet>

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

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

  • AnyEncodable<Data>

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

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

  • AnyEncodable<Date>

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

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

  • AnyEncodable<DateInterval>

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

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

  • AnyEncodable<NSDecimal>

    • [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<IndexPath>

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

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

  • AnyEncodable<IndexSet>

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

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

  • AnyEncodable<Locale>

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

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

  • AnyEncodable<Set<Int>>

    • [JSON] ERROR.
    • [PLIST] ERROR.
  • Set<Int>

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

  • AnyEncodable<String>

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

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

  • AnyEncodable<TimeZone>

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

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

  • AnyEncodable<URL>

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

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

  • AnyEncodable<UUID>

    • [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.

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.😶