File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change 11defprotocol JSON.Encoder do
22 @ moduledoc """
33 A protocol for custom JSON encoding of data structures.
4+
5+ If you have a struct, you can derive the implementation of this protocol
6+ by specifying which fields should be encoded to JSON:
7+
8+ @derive {JSON.Encoder, only: [....]}
9+ defstruct ...
10+
11+ It is also possible to encode all fields or skip some fields via the
12+ `:except` option, although this should be used carefully to avoid
13+ accidentally leaking private information when new fields are added:
14+
15+ @derive JSON.Encoder
16+ defstruct ...
17+
18+ Finally, if you don't own the struct you want to encode to JSON,
19+ you may use Protocol.derive/3 placed outside of any module:
20+
21+ Protocol.derive(JSON.Encoder, NameOfTheStruct, only: [...])
22+ Protocol.derive(JSON.Encoder, NameOfTheStruct)
423 """
524
625 @ undefined_impl_description """
You can’t perform that action at this time.
0 commit comments