codable - What errors can happen when encode with Swift JSONEncoder -


jsonencoder method func encode<t>(_ value: t) throws -> data t : encodable throwable.

i'm wonder why throwable: if value encode not conform encodable, should not pass compiler, should have no error happen @ runtime.

from jsonencoder's source code:

/// - throws: `encodingerror.invalidvalue` if non-conforming floating-point value encountered during encoding, , encoding strategy `.throw`. /// - throws: error if value throws error during encoding. 


debug descriptions errors:

top-level (t.self) did not encode values.

top-level (t.self) encoded null json fragment.

top-level (t.self) encoded number json fragment.

top-level (t.self) encoded string json fragment.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -