|
351 | 351 | Ppx_deriving_json_runtime.of_json_error
|
352 | 352 | "expected a JSON array of length 1";
|
353 | 353 | A)
|
354 |
| - else if Stdlib.( = ) tag "B" then ( |
355 |
| - if Stdlib.( <> ) len 2 then |
356 |
| - Ppx_deriving_json_runtime.of_json_error |
357 |
| - "expected a JSON array of length 2"; |
358 |
| - B (int_of_json (Js.Array.unsafe_get array 1))) |
359 |
| - else if Stdlib.( = ) tag "C" then ( |
360 |
| - if Stdlib.( <> ) len 2 then |
361 |
| - Ppx_deriving_json_runtime.of_json_error |
362 |
| - "expected a JSON array of length 2"; |
363 |
| - let fs = Js.Array.unsafe_get array 1 in |
364 |
| - if |
365 |
| - Stdlib.not |
366 |
| - (Stdlib.( && ) |
367 |
| - (Stdlib.( = ) (Js.typeof fs) "object") |
368 |
| - (Stdlib.( && ) |
369 |
| - (Stdlib.not (Js.Array.isArray fs)) |
370 |
| - (Stdlib.not |
371 |
| - (Stdlib.( == ) |
372 |
| - (Obj.magic fs : 'a Js.null) |
373 |
| - Js.null)))) |
374 |
| - then |
375 |
| - Ppx_deriving_json_runtime.of_json_error |
376 |
| - "expected a JSON object"; |
377 |
| - let fs = |
378 |
| - (Obj.magic fs : < name : Js.Json.t Js.undefined > Js.t) |
379 |
| - in |
380 |
| - C |
381 |
| - { |
382 |
| - name = |
383 |
| - (match Js.Undefined.toOption fs##name with |
384 |
| - | Stdlib.Option.Some v -> string_of_json v |
385 |
| - | Stdlib.Option.None -> |
386 |
| - Ppx_deriving_json_runtime.of_json_error |
387 |
| - "missing field \"name\""); |
388 |
| - }) |
389 |
| - else Ppx_deriving_json_runtime.of_json_error "invalid JSON" |
| 354 | + else |
| 355 | + let tag = (Obj.magic tag : string) in |
| 356 | + if Stdlib.( = ) tag "B" then ( |
| 357 | + if Stdlib.( <> ) len 2 then |
| 358 | + Ppx_deriving_json_runtime.of_json_error |
| 359 | + "expected a JSON array of length 2"; |
| 360 | + B (int_of_json (Js.Array.unsafe_get array 1))) |
| 361 | + else |
| 362 | + let tag = (Obj.magic tag : string) in |
| 363 | + if Stdlib.( = ) tag "C" then ( |
| 364 | + if Stdlib.( <> ) len 2 then |
| 365 | + Ppx_deriving_json_runtime.of_json_error |
| 366 | + "expected a JSON array of length 2"; |
| 367 | + let fs = Js.Array.unsafe_get array 1 in |
| 368 | + if |
| 369 | + Stdlib.not |
| 370 | + (Stdlib.( && ) |
| 371 | + (Stdlib.( = ) (Js.typeof fs) "object") |
| 372 | + (Stdlib.( && ) |
| 373 | + (Stdlib.not (Js.Array.isArray fs)) |
| 374 | + (Stdlib.not |
| 375 | + (Stdlib.( == ) |
| 376 | + (Obj.magic fs : 'a Js.null) |
| 377 | + Js.null)))) |
| 378 | + then |
| 379 | + Ppx_deriving_json_runtime.of_json_error |
| 380 | + "expected a JSON object"; |
| 381 | + let fs = |
| 382 | + (Obj.magic fs |
| 383 | + : < name : Js.Json.t Js.undefined > Js.t) |
| 384 | + in |
| 385 | + C |
| 386 | + { |
| 387 | + name = |
| 388 | + (match Js.Undefined.toOption fs##name with |
| 389 | + | Stdlib.Option.Some v -> string_of_json v |
| 390 | + | Stdlib.Option.None -> |
| 391 | + Ppx_deriving_json_runtime.of_json_error |
| 392 | + "missing field \"name\""); |
| 393 | + }) |
| 394 | + else |
| 395 | + Ppx_deriving_json_runtime.of_json_error "invalid JSON" |
390 | 396 | else
|
391 | 397 | Ppx_deriving_json_runtime.of_json_error
|
392 | 398 | "expected a non empty JSON array with element being a \
|
|
561 | 567 | Ppx_deriving_json_runtime.of_json_error
|
562 | 568 | "expected a JSON array of length 1";
|
563 | 569 | Some `A)
|
564 |
| - else if Stdlib.( = ) tag "B" then ( |
565 |
| - if Stdlib.( <> ) len 2 then |
566 |
| - Ppx_deriving_json_runtime.of_json_error |
567 |
| - "expected a JSON array of length 2"; |
568 |
| - Some (`B (int_of_json (Js.Array.unsafe_get array 1)))) |
569 | 570 | else
|
570 |
| - match other_of_json_poly x with |
571 |
| - | Some x -> (Some x :> [ `A | `B of int | other ] option) |
572 |
| - | None -> None |
| 571 | + let tag = (Obj.magic tag : string) in |
| 572 | + if Stdlib.( = ) tag "B" then ( |
| 573 | + if Stdlib.( <> ) len 2 then |
| 574 | + Ppx_deriving_json_runtime.of_json_error |
| 575 | + "expected a JSON array of length 2"; |
| 576 | + Some (`B (int_of_json (Js.Array.unsafe_get array 1)))) |
| 577 | + else |
| 578 | + match other_of_json_poly x with |
| 579 | + | Some x -> (Some x :> [ `A | `B of int | other ] option) |
| 580 | + | None -> None |
573 | 581 | else
|
574 | 582 | Ppx_deriving_json_runtime.of_json_error
|
575 | 583 | "expected a non empty JSON array with element being a \
|
|
755 | 763 | Ppx_deriving_json_runtime.of_json_error
|
756 | 764 | "expected a JSON array of length 1";
|
757 | 765 | A)
|
758 |
| - else if Stdlib.( = ) tag "Fix" then ( |
759 |
| - if Stdlib.( <> ) len 2 then |
760 |
| - Ppx_deriving_json_runtime.of_json_error |
761 |
| - "expected a JSON array of length 2"; |
762 |
| - Fix (recur_of_json (Js.Array.unsafe_get array 1))) |
763 |
| - else Ppx_deriving_json_runtime.of_json_error "invalid JSON" |
| 766 | + else |
| 767 | + let tag = (Obj.magic tag : string) in |
| 768 | + if Stdlib.( = ) tag "Fix" then ( |
| 769 | + if Stdlib.( <> ) len 2 then |
| 770 | + Ppx_deriving_json_runtime.of_json_error |
| 771 | + "expected a JSON array of length 2"; |
| 772 | + Fix (recur_of_json (Js.Array.unsafe_get array 1))) |
| 773 | + else Ppx_deriving_json_runtime.of_json_error "invalid JSON" |
764 | 774 | else
|
765 | 775 | Ppx_deriving_json_runtime.of_json_error
|
766 | 776 | "expected a non empty JSON array with element being a \
|
|
814 | 824 | Ppx_deriving_json_runtime.of_json_error
|
815 | 825 | "expected a JSON array of length 1";
|
816 | 826 | Some `A)
|
817 |
| - else if Stdlib.( = ) tag "Fix" then ( |
818 |
| - if Stdlib.( <> ) len 2 then |
819 |
| - Ppx_deriving_json_runtime.of_json_error |
820 |
| - "expected a JSON array of length 2"; |
821 |
| - Some |
822 |
| - (`Fix (polyrecur_of_json (Js.Array.unsafe_get array 1)))) |
823 |
| - else None |
| 827 | + else |
| 828 | + let tag = (Obj.magic tag : string) in |
| 829 | + if Stdlib.( = ) tag "Fix" then ( |
| 830 | + if Stdlib.( <> ) len 2 then |
| 831 | + Ppx_deriving_json_runtime.of_json_error |
| 832 | + "expected a JSON array of length 2"; |
| 833 | + Some |
| 834 | + (`Fix |
| 835 | + (polyrecur_of_json (Js.Array.unsafe_get array 1)))) |
| 836 | + else None |
824 | 837 | else
|
825 | 838 | Ppx_deriving_json_runtime.of_json_error
|
826 | 839 | "expected a non empty JSON array with element being a \
|
|
882 | 895 | Ppx_deriving_json_runtime.of_json_error
|
883 | 896 | "expected a JSON array of length 1";
|
884 | 897 | A)
|
885 |
| - else if Stdlib.( = ) tag "b_aliased" then ( |
886 |
| - if Stdlib.( <> ) len 1 then |
887 |
| - Ppx_deriving_json_runtime.of_json_error |
888 |
| - "expected a JSON array of length 1"; |
889 |
| - B) |
890 |
| - else Ppx_deriving_json_runtime.of_json_error "invalid JSON" |
| 898 | + else |
| 899 | + let tag = (Obj.magic tag : string) in |
| 900 | + if Stdlib.( = ) tag "b_aliased" then ( |
| 901 | + if Stdlib.( <> ) len 1 then |
| 902 | + Ppx_deriving_json_runtime.of_json_error |
| 903 | + "expected a JSON array of length 1"; |
| 904 | + B) |
| 905 | + else Ppx_deriving_json_runtime.of_json_error "invalid JSON" |
891 | 906 | else
|
892 | 907 | Ppx_deriving_json_runtime.of_json_error
|
893 | 908 | "expected a non empty JSON array with element being a \
|
|
940 | 955 | Ppx_deriving_json_runtime.of_json_error
|
941 | 956 | "expected a JSON array of length 1";
|
942 | 957 | Some `a)
|
943 |
| - else if Stdlib.( = ) tag "b" then ( |
944 |
| - if Stdlib.( <> ) len 1 then |
945 |
| - Ppx_deriving_json_runtime.of_json_error |
946 |
| - "expected a JSON array of length 1"; |
947 |
| - Some `b) |
948 |
| - else None |
| 958 | + else |
| 959 | + let tag = (Obj.magic tag : string) in |
| 960 | + if Stdlib.( = ) tag "b" then ( |
| 961 | + if Stdlib.( <> ) len 1 then |
| 962 | + Ppx_deriving_json_runtime.of_json_error |
| 963 | + "expected a JSON array of length 1"; |
| 964 | + Some `b) |
| 965 | + else None |
949 | 966 | else
|
950 | 967 | Ppx_deriving_json_runtime.of_json_error
|
951 | 968 | "expected a non empty JSON array with element being a \
|
|
1006 | 1023 | Ppx_deriving_json_runtime.of_json_error
|
1007 | 1024 | "expected a JSON array of length 2";
|
1008 | 1025 | A (a_of_json (Js.Array.unsafe_get array 1)))
|
1009 |
| - else if Stdlib.( = ) tag "B" then ( |
1010 |
| - if Stdlib.( <> ) len 2 then |
1011 |
| - Ppx_deriving_json_runtime.of_json_error |
1012 |
| - "expected a JSON array of length 2"; |
1013 |
| - B (b_of_json (Js.Array.unsafe_get array 1))) |
1014 |
| - else Ppx_deriving_json_runtime.of_json_error "invalid JSON" |
| 1026 | + else |
| 1027 | + let tag = (Obj.magic tag : string) in |
| 1028 | + if Stdlib.( = ) tag "B" then ( |
| 1029 | + if Stdlib.( <> ) len 2 then |
| 1030 | + Ppx_deriving_json_runtime.of_json_error |
| 1031 | + "expected a JSON array of length 2"; |
| 1032 | + B (b_of_json (Js.Array.unsafe_get array 1))) |
| 1033 | + else Ppx_deriving_json_runtime.of_json_error "invalid JSON" |
1015 | 1034 | else
|
1016 | 1035 | Ppx_deriving_json_runtime.of_json_error
|
1017 | 1036 | "expected a non empty JSON array with element being a string"
|
|
1368 | 1387 | if Stdlib.( > ) len 0 then
|
1369 | 1388 | let tag = Js.Array.unsafe_get array 0 in
|
1370 | 1389 | if Stdlib.( = ) (Js.typeof tag) "string" then
|
1371 |
| - let tag = (Obj.magic tag : string) in |
1372 | 1390 | match one_of_json_poly x with
|
1373 | 1391 | | Some x -> (Some x :> [ one | other ] option)
|
1374 | 1392 | | None -> (
|
|
0 commit comments