Skip to content

Commit 48ebeda

Browse files
committed
port fields_derivers to 5.2.1
1 parent 09e4102 commit 48ebeda

File tree

1 file changed

+28
-27
lines changed

1 file changed

+28
-27
lines changed

src/lib/fields_derivers_json/fields_derivers_json.ml

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
open Core_kernel
1+
open Core
22
open Fieldslib
33

44
module To_yojson = struct
@@ -30,12 +30,12 @@ module To_yojson = struct
3030
let rest = !(acc#to_json_accumulator) in
3131
acc#to_json_accumulator :=
3232
( 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 )
3939
:: rest ;
4040
((fun _ -> failwith "Unused"), acc)
4141

@@ -119,24 +119,25 @@ module Of_yojson = struct
119119
let map = !(finished_obj#of_json_creator) in
120120
!(t_field#map)
121121
( 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 ) )
140141
in
141142
(creator, acc_obj)
142143

@@ -285,8 +286,8 @@ let%test_module "Test" =
285286

286287
let full_derivers = both_json @@ o ()
287288

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)" =
290291
[%test_eq: string]
291292
(Yojson_version.to_yojson Yojson_version.v |> Yojson.Safe.to_string)
292293
(!(full_derivers#to_json) v |> Yojson.Safe.to_string)

0 commit comments

Comments
 (0)