Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1661)

Issue 4918051: code review 4918051: json: add struct tag option to wrap literals in strings (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
8 years, 7 months ago by bradfitz
Modified:
8 years, 7 months ago
Reviewers:
CC:
rsc, gustavo_niemeyer.net, golang-dev
Visibility:
Public.

Description

json: add struct tag option to wrap literals in strings Since JavaScript doesn't have [u]int64 types, some JSON APIs encode such types as strings to avoid losing precision. This adds a new struct tag option ",string" to cause fields to be wrapped in JSON strings on encoding and unwrapped from strings when decoding.

Patch Set 1 #

Patch Set 2 : diff -r 7860bad4407f https://go.googlecode.com/hg/ #

Patch Set 3 : diff -r 7860bad4407f https://go.googlecode.com/hg/ #

Patch Set 4 : diff -r f8e4df3c4048 https://go.googlecode.com/hg/ #

Patch Set 5 : diff -r f8e4df3c4048 https://go.googlecode.com/hg/ #

Total comments: 11

Patch Set 6 : diff -r e33629f044a8 https://go.googlecode.com/hg #

Patch Set 7 : diff -r e33629f044a8 https://go.googlecode.com/hg #

Patch Set 8 : diff -r 73c091a3fc96 https://go.googlecode.com/hg #

Unified diffs Side-by-side diffs Delta from patch set Stats (+175 lines, -32 lines) Patch
M src/pkg/json/Makefile View 1 2 3 1 chunk +1 line, -0 lines 0 comments Download
M src/pkg/json/decode.go View 1 2 3 4 5 7 chunks +18 lines, -14 lines 0 comments Download
M src/pkg/json/decode_test.go View 1 2 3 4 chunks +5 lines, -0 lines 0 comments Download
M src/pkg/json/encode.go View 1 2 3 4 5 6 8 chunks +41 lines, -18 lines 0 comments Download
M src/pkg/json/encode_test.go View 1 2 3 2 chunks +38 lines, -0 lines 0 comments Download
A src/pkg/json/tags.go View 1 2 3 4 5 1 chunk +44 lines, -0 lines 0 comments Download
A src/pkg/json/tags_test.go View 1 2 3 4 5 1 chunk +28 lines, -0 lines 0 comments Download

Messages

Total messages: 18
bradfitz
Hello golang-dev@googlegroups.com (cc: golang-dev@googlegroups.com), I'd like you to review this change to https://go.googlecode.com/hg/
8 years, 7 months ago (2011-08-24 09:42:37 UTC) #1
bradfitz
This one's for discussion. I anticipate the JSON != JavaScript argument already, but let me ...
8 years, 7 months ago (2011-08-24 09:47:03 UTC) #2
rsc
I would like to keep the json core clean instead of full of heuristics. There ...
8 years, 7 months ago (2011-08-24 15:06:12 UTC) #3
gustavo_niemeyer.net
> I'd like to use the current MarshalJSON > and UnmarshalJSON callouts. As a minor ...
8 years, 7 months ago (2011-08-24 17:19:31 UTC) #4
rsc
I thought I already fixed that. On Aug 24, 2011 1:19 PM, "Gustavo Niemeyer" <gustavo@niemeyer.net> ...
8 years, 7 months ago (2011-08-24 17:31:52 UTC) #5
gustavo_niemeyer.net
> I thought I already fixed that. changeset: 9370:9009fa15f80e user: Russ Cox <rsc@golang.org> date: Wed ...
8 years, 7 months ago (2011-08-24 17:44:18 UTC) #6
bradfitz
I could have defined those types in my own package, too. My "bleed out to ...
8 years, 7 months ago (2011-08-24 22:05:37 UTC) #7
rsc
> I'd rather give callers a pure struct with sane types and keep the > ...
8 years, 7 months ago (2011-08-25 02:40:54 UTC) #8
bradfitz
Hello golang-dev@googlegroups.com, rsc@golang.org, gustavo@niemeyer.net (cc: golang-dev@googlegroups.com), Please take another look.
8 years, 7 months ago (2011-08-26 09:38:20 UTC) #9
bradfitz
Russ, Here's my first attempt at implementing your earlier counter-proposal of a ",string" option. I ...
8 years, 7 months ago (2011-08-26 09:42:50 UTC) #10
rsc
LGTM Nice how it fit in. http://codereview.appspot.com/4918051/diff/17001/src/pkg/json/decode.go File src/pkg/json/decode.go (right): http://codereview.appspot.com/4918051/diff/17001/src/pkg/json/decode.go#newcode529 src/pkg/json/decode.go:529: var s string ...
8 years, 7 months ago (2011-08-26 20:35:44 UTC) #11
bradfitz
http://codereview.appspot.com/4918051/diff/17001/src/pkg/json/decode.go File src/pkg/json/decode.go (right): http://codereview.appspot.com/4918051/diff/17001/src/pkg/json/decode.go#newcode529 src/pkg/json/decode.go:529: var s string On 2011/08/26 20:35:44, rsc wrote: > ...
8 years, 7 months ago (2011-08-29 19:06:12 UTC) #12
bradfitz
Hello rsc@golang.org, gustavo@niemeyer.net (cc: golang-dev@googlegroups.com), Please take another look.
8 years, 7 months ago (2011-08-29 19:06:14 UTC) #13
rsc
http://codereview.appspot.com/4918051/diff/17001/src/pkg/json/encode.go File src/pkg/json/encode.go (right): http://codereview.appspot.com/4918051/diff/17001/src/pkg/json/encode.go#newcode253 src/pkg/json/encode.go:253: var writeString func(string) On 2011/08/29 19:06:12, bradfitz wrote: > ...
8 years, 7 months ago (2011-08-29 19:23:37 UTC) #14
bradfitz
Hello rsc@golang.org, gustavo@niemeyer.net (cc: golang-dev@googlegroups.com), Please take another look.
8 years, 7 months ago (2011-08-29 19:32:40 UTC) #15
bradfitz
On Mon, Aug 29, 2011 at 12:23 PM, <rsc@golang.org> wrote: > > http://codereview.appspot.com/**4918051/diff/17001/src/pkg/** > json/encode.go<http://codereview.appspot.com/4918051/diff/17001/src/pkg/json/encode.go> ...
8 years, 7 months ago (2011-08-29 19:32:59 UTC) #16
rsc
LGTM
8 years, 7 months ago (2011-08-29 19:37:42 UTC) #17
bradfitz
8 years, 7 months ago (2011-08-29 19:46:37 UTC) #18
*** Submitted as http://code.google.com/p/go/source/detail?r=ba6daf799367 ***

json: add struct tag option to wrap literals in strings

Since JavaScript doesn't have [u]int64 types, some JSON APIs
encode such types as strings to avoid losing precision.

This adds a new struct tag option ",string" to cause
fields to be wrapped in JSON strings on encoding
and unwrapped from strings when decoding.

R=rsc, gustavo
CC=golang-dev
http://codereview.appspot.com/4918051
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b