Skip to content
This repository has been archived by the owner on Jun 22, 2021. It is now read-only.

Implement JSON RW methods #75

Open
kriskowal opened this issue Oct 17, 2015 · 0 comments
Open

Implement JSON RW methods #75

kriskowal opened this issue Oct 17, 2015 · 0 comments

Comments

@kriskowal
Copy link
Contributor

We stringify and parse JSON or POJO and convert to and from Thrift, both in Node.js to allow endpoints implementations to be shared between JSON and Thrift transport encodings, but even more importantly in TCurl for parsing arguments and formatting responses. As such, we should maximize the expressiveness of JSON as a medium for Thrift.

JSON stringify and parse are adequate for converting thrift model objects to and from their JSON/POJO form up to a point. Limitations:

  • i64: JavaScript’s JSON stringify and parse can only handle resolutions known by JavaScript. jq and Thrift do not have this limitation and Long.js can stringify numbers up to their full 64 bit resolution.
  • timestamps: We standardize timestamps in Thrift as numbers of miliseconds in 64 bit resolution to avoid slow and unnecessary date parsing and formatting. However, this format is not idiomatic or visually useful for JSON. With the i64 (js.type = 'Date') annotation and the specialized I64DateRW we have an opportunity to implement an alternate JSON representation using ISO timestamps, when both reading JSON (as with TCurl arguments) or writing (As with TCurl output).

I propose that we implement stringify(value):text and parse(text, offset):Result<value> methods on each ThriftRW to improve TCurl user experience. With this change, given a Thrift IDL with js.type annotations, it will be possible to:

  1. pass an ISO string as an argument in the position of an i64 (js.type = 'Date')
  2. read an i64 (js.type = 'Date') as an ISO string from TCurl and jq output.
  3. pass an arbitrary precision number as an argument in the position of i64 types.
  4. read an i64 with all precision in TCurl and jq output.

Likewise, due consideration can be made for binary encoding (hex or \u0000) and flexibility made for future specialization as needed.

cc @abhinav @malandrew

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant