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 JSON serialization methods for Date types #1002

Draft
wants to merge 2 commits into
base: 5.0
Choose a base branch
from

Conversation

bigmontz
Copy link
Contributor

This enables JSON.stringify to serialize these data types to ISO strings instead of JS Objects. Transformation loops and other boiler plates like the following with this method introduction.

For instance, the following code:

if (result.records) {
    for (const record of result.records) {
        for (const recordKey of record.keys) {
            const object = record.get(recordKey);
            if (!Array.isArray(object)) {
                for (const key in object) {
                    if (object.hasOwnProperty(key) && isDateTime(object[key])) {
                        object[key] = object[key].toString();
                    }
                }
            }
        }
    }
}

This snippet can be replaced by this other one:

if (result.records) {
    for (const record of result.records) {
      const object = record.toObject()
    }
}

This enables `JSON.stringify` to serialize these data types to ISO strings instead of JS Objects.
Transformation loops and other bollerplates like the following with this method introduction.

For instance, the following code:

```javascript
if (result.records) {
    for (const record of result.records) {
        for (const recordKey of record.keys) {
            const object = record.get(recordKey);
            if (!Array.isArray(object)) {
                for (const key in object) {
                    if (object.hasOwnProperty(key) && isDateTime(object[key])) {
                        object[key] = object[key].toString();
                    }
                }
            }
        }
    }
}
```
This snippet can be replaced by this other one:

```javascript
if (result.records) {
    for (const record of result.records) {
      const object = record.toObject()
    }
}
```
@bigmontz bigmontz linked an issue Sep 20, 2022 that may be closed by this pull request
@bigmontz bigmontz marked this pull request as draft September 21, 2022 11:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Disable automatic parsing of DateTime values
1 participant