|
1 | | -open Core_kernel |
| 1 | +open Core |
2 | 2 | open Fieldslib |
3 | 3 |
|
4 | 4 | module To_yojson = struct |
@@ -30,12 +30,12 @@ module To_yojson = struct |
30 | 30 | let rest = !(acc#to_json_accumulator) in |
31 | 31 | acc#to_json_accumulator := |
32 | 32 | ( if annotations.skip || !(t_field#skip) then None |
33 | | - else |
34 | | - ( Option.value annotations.name |
35 | | - ~default:(Fields_derivers.name_under_to_camel field) |
36 | | - , fun x -> !(t_field#to_json) (!(t_field#contramap) (Field.get field x)) |
37 | | - ) |
38 | | - |> Option.return ) |
| 33 | + else |
| 34 | + ( Option.value annotations.name |
| 35 | + ~default:(Fields_derivers.name_under_to_camel field) |
| 36 | + , fun x -> |
| 37 | + !(t_field#to_json) (!(t_field#contramap) (Field.get field x)) ) |
| 38 | + |> Option.return ) |
39 | 39 | :: rest ; |
40 | 40 | ((fun _ -> failwith "Unused"), acc) |
41 | 41 |
|
@@ -119,24 +119,25 @@ module Of_yojson = struct |
119 | 119 | let map = !(finished_obj#of_json_creator) in |
120 | 120 | !(t_field#map) |
121 | 121 | ( if annotations.skip || !(t_field#skip) then |
122 | | - match skip_data with |
123 | | - | Some x -> |
124 | | - x |
125 | | - | None -> |
126 | | - failwith |
127 | | - "If you are skipping a field in of_json but intend on building \ |
128 | | - this field, you must provide skip_data to add_field!" |
129 | | - else |
130 | | - !(t_field#of_json) |
131 | | - (let name = |
132 | | - Option.value annotations.name |
133 | | - ~default:(Fields_derivers.name_under_to_camel field) |
134 | | - in |
135 | | - match Map.find map name with |
136 | | - | None -> |
137 | | - raise (Field_not_found name) |
138 | | - | Some x -> |
139 | | - x ) ) |
| 122 | + match skip_data with |
| 123 | + | Some x -> |
| 124 | + x |
| 125 | + | None -> |
| 126 | + failwith |
| 127 | + "If you are skipping a field in of_json but intend on \ |
| 128 | + building this field, you must provide skip_data to \ |
| 129 | + add_field!" |
| 130 | + else |
| 131 | + !(t_field#of_json) |
| 132 | + (let name = |
| 133 | + Option.value annotations.name |
| 134 | + ~default:(Fields_derivers.name_under_to_camel field) |
| 135 | + in |
| 136 | + match Map.find map name with |
| 137 | + | None -> |
| 138 | + raise (Field_not_found name) |
| 139 | + | Some x -> |
| 140 | + x ) ) |
140 | 141 | in |
141 | 142 | (creator, acc_obj) |
142 | 143 |
|
@@ -285,8 +286,8 @@ let%test_module "Test" = |
285 | 286 |
|
286 | 287 | let full_derivers = both_json @@ o () |
287 | 288 |
|
288 | | - let%test_unit "folding creates a yojson object we expect (modulo camel \ |
289 | | - casing)" = |
| 289 | + let%test_unit |
| 290 | + "folding creates a yojson object we expect (modulo camel casing)" = |
290 | 291 | [%test_eq: string] |
291 | 292 | (Yojson_version.to_yojson Yojson_version.v |> Yojson.Safe.to_string) |
292 | 293 | (!(full_derivers#to_json) v |> Yojson.Safe.to_string) |
|
0 commit comments