目录
目录README.md

@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}.

关于
37.0 KB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

©Copyright 2023 CCF 开源发展委员会
Powered by Trustie& IntelliDE 京ICP备13000930号