Skip to content

v0.3.0

Compare
Choose a tag to compare
@gabbhack gabbhack released this 04 Feb 16:35
· 23 commits to master since this release

Breaks

  • Aliases, like type Foo = Bar, no longer supported by makeDe\Serializable macros. You should call make* macro on original type.
  • nil now serialized as the None token instead of dereference error. How to serialize the None token is up to each library. deser_json, for example, serializes it as null. You can skip serializing nil with the skipSerializeIf pragma.

Features

  • Inheritance support. Now all fields of parent objects are serialized together with the fields of child objects. Since the feature is called inheritance, the pragmas are "inherited" from parent objects.
  • renamed, renameSerialize, renameDeserialize can now accept RenameCase enum. Example:
type Foo = object
   firstName {.renamed(SnakeCase).}: string
  • Objects with more than one case on the same level are now supported. An example of how Message deserialization from the Telegram Bot API might look:
type
  MessageContentType = enum
    Text, Audio
  Message {.renameAll(SnakeCase).} = object
    case contentType {.untagged.}: MessageContentType
    of Text:
      text: string
    of Audio:
     audio: Audio

    case isForward {.untagged.}: bool
    of true:
      forwardFrom: User
    of false:
      discard
  • New {.aliases.} pragma. Deserialize field from the given names or from its Nim name. Accepts strings and RenameCase values.
type
  User = object
    nickName {.aliases("username", "login", SnakeCase).}: string
type
  User {.skipPrivate.} = object
    id*: int
    name*: string
    passwordHash: string

Fixes

  • Pragmas that take no arguments can now be used without brackets: {.defaultValue().} -> {.defaultValue.}
  • Correct code generation for case objects having of with multiple conditions
type Foo = object
  case kind: bool
  of true, false:
    discard