Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add serializeAnyToJson and unserializeAnyFromJsonUnsafe #3058

Closed
wants to merge 3 commits into from

Commits on Sep 23, 2018

  1. Add serializeAnyToJson and unserializeAnyFromJsonUnsafe

    See docs for more info. This also retains debug information if bsc was
    with with `-bs-g`.
    
    ```
    [anyToJson value] turns any [value] into a JSON object
    
    This will throw an error if there are any functions anywhere in the value.
    
    [unsafeAnyFromJson json] converts a serialized JSON object back into the bucklescript runtime value.
    
    Warning: marshaling is currently not type-safe. The type of marshaled data is not transmitted along
    the value of the data, making it impossible to check that the data read back possesses the type expected
    by the context. The return type of this function is given as 'a, but this is misleading: the returned
    OCaml value does not possess type 'a for all 'a; it has one, unique type which cannot be determined at
    compile-time.
    
    The programmer should explicitly give the expected type of the returned value, using the following syntax:
    
      (Js.Json.unserializeAnyFromJsonUnsafe json : type)
    
    Anything can happen at run-time if the object does not correspond to the assumed type.
    ```
    
    Test Plan:
    ```
    make libs
    make -C jscomp/tests all
    ./node_modules/.bin/mocha jscomp/test/js_json_test.js
    ```
    jaredly committed Sep 23, 2018
    Configuration menu
    Copy the full SHA
    7a84aba View commit details
    Browse the repository at this point in the history
  2. add a note

    jaredly committed Sep 23, 2018
    Configuration menu
    Copy the full SHA
    9519934 View commit details
    Browse the repository at this point in the history
  3. rebuild after rebase

    jaredly committed Sep 23, 2018
    Configuration menu
    Copy the full SHA
    e737aa8 View commit details
    Browse the repository at this point in the history