gserde
warning: alpha package with poor code hygiene, including assert/panic/todo statements. Use understanding that this package is not ready for primetime.
gleam add gserde
usage
- Create custom type with a singular variant constructor:
- Run
gleam run -m gserde
- Observe
src/foo_json.gleam
, which has the goodies you need for json (de)serialization.
// src/foo.gleam
import gleam/option.{type Option}
pub type FooJSON {
Foo(
a_bool: Bool,
b_int: Int,
c_float: Float,
d_two_tuple: #(Int, String),
e_option_int: Option(Int),
f_string_list: List(String),
)
}
// src/my_module.gleam
import foo
import foo_json
pub fn serialization_identity_test() {
let foo_1 = foo.Foo(..)
let foo_2 = foo_1
|> foo_json.to_string // ๐
|> foo_json.from_string // ๐
foo_1 == foo_2
}
todo
- complete all cases
- remove all invocations of assert/panic/todo
- support non-gleam primitive types
- handle all module references properly
Further documentation can be found at https://hexdocs.pm/gserde.
Development
gleam test # Run the tests