@@ -8,24 +8,29 @@ defprotocol JSON.Encoder do
8
8
If you have a struct, you can derive the implementation of this protocol
9
9
by specifying which fields should be encoded to JSON:
10
10
11
- @derive {JSON.Encoder, only: [.... ]}
11
+ @derive {JSON.Encoder, only: [...]}
12
12
defstruct ...
13
13
14
- It is also possible to encode all fields or skip some fields via the
15
- `:except` option:
14
+ Additionally, you can exclude specific fields using the `:except` option or
15
+ encode all fields by omitting both options entirely, but these should be used
16
+ with caution:
17
+
18
+ @derive {JSON.Encoder, except: [...]}
19
+ defstruct ...
16
20
17
21
@derive JSON.Encoder
18
22
defstruct ...
19
23
20
24
> #### Leaking Private Information {: .error}
21
25
>
22
- > The `:except` approach should be used carefully to avoid
23
- > accidentally leaking private information when new fields are added .
26
+ > Prefer using `:only` to avoid accidentally leaking private information when
27
+ > new fields are added. Other approaches should be used with auction .
24
28
25
- Finally, if you don't own the struct you want to encode to JSON,
26
- you may use `Protocol.derive/3` placed outside of any module :
29
+ You can also use `Protocol.derive/3` if you don't own the struct that you want
30
+ to encode to JSON :
27
31
28
32
Protocol.derive(JSON.Encoder, NameOfTheStruct, only: [...])
33
+ Protocol.derive(JSON.Encoder, NameOfTheStruct, except: [...])
29
34
Protocol.derive(JSON.Encoder, NameOfTheStruct)
30
35
31
36
"""
0 commit comments