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

support time.Time serialization #14

Closed
iivvoo opened this issue Jun 13, 2019 · 3 comments
Closed

support time.Time serialization #14

iivvoo opened this issue Jun 13, 2019 · 3 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@iivvoo
Copy link

iivvoo commented Jun 13, 2019

jingo currently can't serialize time.Time. By default it will serialize to {}, and using stringify it won't give a proper ISO8601 (?) representation.

I've attempted to work around this using a fallback to the json.Marshaller interface (see #13 ) but explicitly supporting time.Time is more efficient and probably as effective.

@kungfusheep
Copy link
Collaborator

Thanks

From #13 (comment)

The Time package already offers support for AppendFormat([]byte, layout string) []byte, so if we had 1st class support we would be able to do so without the additional alloc needed by MarshalJSON.

I propose adding ptrTimeToBuf(unsafe.Pointer, *Buffer) to ptrconvert.go then adding a hook within the encoders to use that for time.Time.

The function would behave the same way the rest of the append functions in that file behave and would nominate time.RFC3339Nano as the layout. This then puts the output in-line with what you may expect from JSON.stringify within a browser.

@kungfusheep
Copy link
Collaborator

Cheers @johngillott

@johngillott
Copy link
Contributor

No problem 👍 @kungfusheep

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants