2 ms·
> JSON serialization/deserialization layer Why do you need a whole "layer" for this? I recently wrote a microservice in Go with a JSON-emitting RESTy API, and
by majewsky 10y ago
> JSON serialization/deserialization layer
Why do you need a whole "layer" for this? I recently wrote a microservice in Go with a JSON-emitting RESTy API, and my JSON serialization layer is two functions for a total of 20 limes: https://github.com/sapcc/limes/blob/0735bd6de4e49f900ab8d97aec88ac1beeeb9f55/pkg/api/core.go#L102-L135 https://github.com/sapcc/limes/blob/0735bd6de4e49f900ab8d97a... (ignore the unrelated function inbetween; I cannot select non-contiguous areas in GitHub source code listings)
- int_19h 10y agoI think what OP means is a layer in a sense of mapping JSON to your own data types. You just invoke json.Marshal/Unmarshal here, which deserializes into maps and arrays of interface{} - i.e. effectively an untyped data structure.
- majewsky 10y agoNo, it doesn't. json.Un/Marshal understand all data types; you just need to annotate fields in structs with their JSON field names.