-
Notifications
You must be signed in to change notification settings - Fork 73
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 JSONObjectToYAMLObject #14
Conversation
/assign @apelisse |
f7df8d8
to
d374b2b
Compare
d374b2b
to
e32b7fd
Compare
yaml_test.go
Outdated
"map": map[string]interface{}{"foo": "bar"}, | ||
"slice": []interface{}{"foo", "bar"}, | ||
"string": string("foo"), | ||
"uint64 big": float64(math.Pow(2, 63)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{"big negative", float64(math.Pow(-2, 63)}
will resolve to:
{"big negative", int(-9223372036854775808)}
on 64bit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also what happens if we pass a big int64(x)
value on a 32bit word size?
would the value be truncated by translating to int()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-float64(math.Pow(2, 63)
round trips to a float64 non-precise number with yaml.Unmarshal(json.Marshal(x))
although it fits into int64.
/assign @liggitt @neolit123 |
e32b7fd
to
27e091d
Compare
// string, bool and any other types are unchanged. | ||
func JSONObjectToYAMLObject(j map[string]interface{}) yaml.MapSlice { | ||
if len(j) == 0 { | ||
return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is surprising... doesn't this mean that an empty map doesn't round trip? if so, doesn't that break uses like CRD status (status: {}
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is what the yaml library does, compare the tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm... it's still not quite clear to me who is intending to call this helper method, and whether this len(0) => nil
treatment is going to bite us... any chance we can fix the yaml library instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not that this is just the top-level conversion func. Further down we have jsonToYAMLValue
which is faithful with empty maps.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@liggitt actually this semantics is not that surprising and nothing to change:
A yaml in-memory data structure has interface{}{nil}
for null values. yaml.MapSlice(nil)
is not null, but the empty map. It marshals to {}
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, ok
Is this going in any time soon? |
27e091d
to
c8cac5c
Compare
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: sttts The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
c8cac5c
to
b47e936
Compare
2d3a4e1
to
989bfe4
Compare
989bfe4
to
6872eb0
Compare
/lgtm |
JSONObjectToYAMLObject
is used to convert to a YAML MapSlice representation without going through a byte slice representation, which is too heavy on allocations for some applications.