NullCodable

1.1.0

Property wrapper that encodes `nil` optional values as `null` when encoded using `JSONEncoder`
g-mark/NullCodable

What's New

Version 1.1.0

2020-11-14T03:10:34Z

Adds support for decoding JSON with missing fields.

@NullCodable

@NullCodable is a property wrapper that encodes nil optional values as null when encoded using JSONEncoder.

On its own, JSONEncoder will omit optional properties that are nil - meaning that this:

struct Test: Codable {
  var name: String? = nil
}

will be encoded as: {}.

If for some reason, you would like optional properties that are nil to be encoded in JSON as null, then marking those properties as @NullCodable will do so.

For example, adding @NullCodable like this:

  struct Test: Codable {
    @NullCodable var name: String? = nil
  }

will encode as: {\"name\": null}.

Description

  • Swift Tools 5.1.0
View More Packages from this Author

Dependencies

  • None
Last updated: Mon Nov 21 2022 06:31:42 GMT-0500 (GMT-05:00)