Deser
Deser is a serialization and deserialization library for Nim
Installation
nimble install deser
or
requires "nim >= 1.4.2, deser"
Features
-
Efficient:
deser
does not use reflection or type information at runtime and generates code close to hand-written. Read more about overhead. - Easy to use: simple API for users and data formats developers.
- Functional: use pragmas to manage the serialization and deserialization process.
-
Universal:
deser
is not limited to any data format.
Usage
import macros # https://deser.nim.town/deser.html#manual-limitations
import options, times
import deser, deser_json
type
Foo {.skipSerializeIf(isNone), renameAll(rkSnakeCase).} = object
id: int
someOption: Option[int]
date {.serializeWith(toUnix), deserializeWith(fromUnix).}: Time
const js = """
{
"id": 123,
"some_option": 321,
"date": 1214092800
}
"""
var f = js.parse().to(Foo)
f.someOption = none(int)
assert f.dumps() == """{"id":123,"date":1214092800}"""
Contributing
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Format the code (
nimble pretty
) - Check tests (
nimble test
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request