|
|
|
Created:
14 years, 9 months ago by mikio Modified:
14 years, 8 months ago Reviewers:
CC:
adg, rsc, bradfitz, mattn, gustavo_niemeyer.net, golang-dev Visibility:
Public. |
Descriptionjson: allow using '$' and '-' as the struct field's tag
Patch Set 1 : diff -r add294e751cb https://go.googlecode.com/hg/ #Patch Set 2 : diff -r add294e751cb https://go.googlecode.com/hg/ #
Total comments: 1
Patch Set 3 : diff -r add294e751cb https://go.googlecode.com/hg/ #Patch Set 4 : diff -r add294e751cb https://go.googlecode.com/hg/ #Patch Set 5 : diff -r add294e751cb https://go.googlecode.com/hg/ #
Total comments: 1
Patch Set 6 : diff -r 67b160cd5fa4 https://go.googlecode.com/hg/ #
Total comments: 2
Patch Set 7 : diff -r 6fe6dae00ad1 https://go.googlecode.com/hg/ #Patch Set 8 : diff -r 57c578e0cff2 https://go.googlecode.com/hg/ #
MessagesTotal messages: 27
Hello golang-dev@googlegroups.com (cc: golang-dev@googlegroups.com), I'd like you to review this change to https://go.googlecode.com/hg/
Sign in to reply to this message.
I was thinking that now that there's an explicit json: required we might as well accept any tag that can be a valid json string constant.
Sign in to reply to this message.
Please add a test. Go makes it too easy. No excuse not to. Failure to add a test will result in my intentionally trying to regress your patch in a future patch of my own. :-) On Thu, Jun 30, 2011 at 3:27 PM, <mikioh.mikioh@gmail.com> wrote: > Reviewers: golang-dev_googlegroups.com, > > Message: > Hello golang-dev@googlegroups.com (cc: golang-dev@googlegroups.com), > > I'd like you to review this change to > https://go.googlecode.com/hg/ > > > Description: > json: enable hyphen as a valid tag character > > Please review this at http://codereview.appspot.com/**4625081/<http://codereview.appspot.com/4625081/> > > Affected files: > M src/pkg/json/encode.go > > > Index: src/pkg/json/encode.go > ==============================**==============================**======= > --- a/src/pkg/json/encode.go > +++ b/src/pkg/json/encode.go > @@ -40,7 +40,7 @@ > // becomes a member of the object. By default the object's key string > // is the struct field name. If the struct field's tag has a "json" key > with a > // value that is a non-empty string consisting of only Unicode letters, > -// digits, and underscores, that value will be used as the object key. > +// digits, hyphens, and underscores, that value will be used as the object > key. > // For example, the field tag `json:"myName"` says to use "myName" > // as the object key. > // > @@ -316,7 +316,7 @@ > return false > } > for _, c := range s { > - if c != '_' && !unicode.IsLetter(c) && !unicode.IsDigit(c) > { > + if c != '_' && c != '-' && !unicode.IsLetter(c) && > !unicode.IsDigit(c) { > return false > } > } > > >
Sign in to reply to this message.
Hello golang-dev@googlegroups.com, rsc@golang.org, bradfitz@golang.org (cc: golang-dev@googlegroups.com), Please take another look.
Sign in to reply to this message.
http://codereview.appspot.com/4625081/diff/11002/src/pkg/json/encode.go File src/pkg/json/encode.go (right): http://codereview.appspot.com/4625081/diff/11002/src/pkg/json/encode.go#newco... src/pkg/json/encode.go:324: if unicode.IsLetter(c) || unicode.IsDigit(c) { original code return true if never find invalid characters. but new code return true when find first valid character. When first characetr is valid, and that include invalid character, this function return true. is this a ok? i'm not sure, i don't know why this CL is needed, this change seems to be broken.
Sign in to reply to this message.
On Fri, Jul 1, 2011 at 12:44 PM, <mattn.jp@gmail.com> wrote: > original code return true if never find invalid characters. > but new code return true when find first valid character. oops, thx.
Sign in to reply to this message.
Hello golang-dev@googlegroups.com, rsc@golang.org, bradfitz@golang.org, mattn.jp@gmail.com (cc: golang-dev@googlegroups.com), Please take another look.
Sign in to reply to this message.
Hello golang-dev@googlegroups.com, rsc@golang.org, bradfitz@golang.org, mattn.jp@gmail.com (cc: golang-dev@googlegroups.com), Please take another look.
Sign in to reply to this message.
LGTM test passed. On 2011/07/01 04:17:37, mikioh wrote: > Hello mailto:golang-dev@googlegroups.com, mailto:rsc@golang.org, mailto:bradfitz@golang.org, > mailto:mattn.jp@gmail.com (cc: mailto:golang-dev@googlegroups.com), > > Please take another look.
Sign in to reply to this message.
Hello golang-dev@googlegroups.com, rsc@golang.org, bradfitz@golang.org, mattn.jp@gmail.com (cc: golang-dev@googlegroups.com), Please take another look.
Sign in to reply to this message.
Handing off to adg. http://codereview.appspot.com/4625081/diff/5003/src/pkg/json/encode.go File src/pkg/json/encode.go (right): http://codereview.appspot.com/4625081/diff/5003/src/pkg/json/encode.go#newcode41 src/pkg/json/encode.go:41: // is the struct field name. If the struct field's tag has a "json" key with a I really think this should be If the struct field's tag has a "json" key, its value will be used as the object key. with no restrictions on the key, since it is after all a quoted string. The restrictions were introduced to avoid misusing proto buffer tags as json tags. We have a better story for that now.
Sign in to reply to this message.
On Fri, Jul 1, 2011 at 11:30 PM, <rsc@golang.org> wrote: > If the struct field's tag has a "json" key, its value will be used as > the object key. > > with no restrictions on the key, since it is after all a quoted string. > The restrictions were introduced to avoid misusing proto buffer > tags as json tags. We have a better story for that now. Yeah, that makes sense. will try.
Sign in to reply to this message.
Hello adg@golang.org, rsc@golang.org, bradfitz@golang.org, mattn.jp@gmail.com (cc: golang-dev@googlegroups.com), Please take another look.
Sign in to reply to this message.
Ping. On Tue, Jul 5, 2011 at 12:17 PM, <mikioh.mikioh@gmail.com> wrote: > Hello adg@golang.org, rsc@golang.org, bradfitz@golang.org, > mattn.jp@gmail.com (cc: golang-dev@googlegroups.com), > > Please take another look. > > > http://codereview.appspot.com/4625081/
Sign in to reply to this message.
Ping. On Fri, Jul 8, 2011 at 9:47 AM, Mikio Hara <mikioh.mikioh@gmail.com> wrote: > Ping. > > On Tue, Jul 5, 2011 at 12:17 PM, <mikioh.mikioh@gmail.com> wrote: > >> Hello adg@golang.org, rsc@golang.org, bradfitz@golang.org, >> mattn.jp@gmail.com (cc: golang-dev@googlegroups.com), >> >> Please take another look. >> >> >> http://codereview.appspot.com/4625081/
Sign in to reply to this message.
http://codereview.appspot.com/4625081/diff/4004/src/pkg/json/tagkey_test.go File src/pkg/json/tagkey_test.go (right): http://codereview.appspot.com/4625081/diff/4004/src/pkg/json/tagkey_test.go#n... src/pkg/json/tagkey_test.go:80: case " !\"#$%&'()*+,-./", "0123456789:;<=>?", "@ABCDEFGHIJKLMO", "PQRSTUVWXYZ[\\]^_", "`abcdefghijklmno", "pqrstuvwxyz{|}~\x7f", "いろはにほへと": This is a bit messy. Add the key name to the test cases so we can just look for the specific key/value pair.
Sign in to reply to this message.
Sorry, I have been leaving this to the side while we hammer out what is going to happen with Brad's 'omit zero values' proposal. That had some bearing on whether we accept absolutely anything here.
Sign in to reply to this message.
http://codereview.appspot.com/4625081/diff/4004/src/pkg/json/tagkey_test.go File src/pkg/json/tagkey_test.go (right): http://codereview.appspot.com/4625081/diff/4004/src/pkg/json/tagkey_test.go#n... src/pkg/json/tagkey_test.go:80: case " !\"#$%&'()*+,-./", "0123456789:;<=>?", "@ABCDEFGHIJKLMO", "PQRSTUVWXYZ[\\]^_", "`abcdefghijklmno", "pqrstuvwxyz{|}~\x7f", "いろはにほへと": On 2011/07/13 04:52:06, adg wrote: > This is a bit messy. Add the key name to the test cases so we can just look for > the specific key/value pair. Done.
Sign in to reply to this message.
Hello adg@golang.org, rsc@golang.org, bradfitz@golang.org, mattn.jp@gmail.com (cc: golang-dev@googlegroups.com), Please take another look.
Sign in to reply to this message.
We need a way to give a few options to the json: tag besides the key name. Instead of allowing absolutely anything here, I propose to make the tag value a ,-separated list of things, the first of which is the key name. That would mean you cannot use , in a key name with Go's json package even though you can in JSON. Does that solve your original problem? Russ
Sign in to reply to this message.
> We need a way to give a few options to the json: tag > besides the key name. Instead of allowing absolutely > anything here, I propose to make the tag value a ,-separated > list of things, the first of which is the key name. > That would mean you cannot use , in a key name > with Go's json package even though you can in JSON. FWIW, I'm using "/" right now in gobson/mgo to separate flags from key name, in a similar way you suggest. I'm still holding the changes to tag handling (which means it's broken with the latest weekly), and would be happy to use a common convention there. Switching to , sounds reasonable to me. -- Gustavo Niemeyer http://niemeyer.net http://niemeyer.net/plus http://niemeyer.net/twitter http://niemeyer.net/blog -- I never filed a patent.
Sign in to reply to this message.
On Wed, Jul 13, 2011 at 3:04 PM, Gustavo Niemeyer <gustavo@niemeyer.net>wrote: > > We need a way to give a few options to the json: tag > > besides the key name. Instead of allowing absolutely > > anything here, I propose to make the tag value a ,-separated > > list of things, the first of which is the key name. > > That would mean you cannot use , in a key name > > with Go's json package even though you can in JSON. > > FWIW, I'm using "/" right now in gobson/mgo to separate flags from key > name, in a similar way you suggest. I'm still holding the changes to > tag handling (which means it's broken with the latest weekly), and > would be happy to use a common convention there. Switching to , > sounds reasonable to me. > protobuf picked "," first, so json would follow that for consistency.
Sign in to reply to this message.
Yes, what I just want is parsing "media-types" like hyp-t'd tag/key. On Jul 14, 2011, at 6:23 AM, Russ Cox <rsc@golang.org> wrote: > We need a way to give a few options to the json: tag > besides the key name. Instead of allowing absolutely > anything here, I propose to make the tag value a ,-separated > list of things, the first of which is the key name. > That would mean you cannot use , in a key name > with Go's json package even though you can in JSON. > > Does that solve your original problem? > > Russ
Sign in to reply to this message.
Okay. Let's keep the current restrictions as is, then, and just expand the name set to allow - and $, rather than do everything but comma. Russ
Sign in to reply to this message.
Hello adg@golang.org, rsc@golang.org, bradfitz@golang.org, mattn.jp@gmail.com, gustavo@niemeyer.net (cc: golang-dev@googlegroups.com), Please take another look.
Sign in to reply to this message.
LGTM
Sign in to reply to this message.
*** Submitted as http://code.google.com/p/go/source/detail?r=e09ea45b361e *** json: allow using '$' and '-' as the struct field's tag R=adg, rsc, bradfitz, mattn.jp, gustavo CC=golang-dev http://codereview.appspot.com/4625081 Committer: Russ Cox <rsc@golang.org>
Sign in to reply to this message.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
