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

UPSTREAM: 16964: Preserve int64 data when unmarshaling #5774

Merged
merged 2 commits into from
Nov 7, 2015
Merged

UPSTREAM: 16964: Preserve int64 data when unmarshaling #5774

merged 2 commits into from
Nov 7, 2015

Conversation

liggitt
Copy link
Contributor

@liggitt liggitt commented Nov 6, 2015

Fixes #5557

@liggitt
Copy link
Contributor Author

liggitt commented Nov 6, 2015

[test]

@liggitt liggitt added this to the 1.1.0 milestone Nov 7, 2015
func convertMapNumbers(m map[string]interface{}) error {
var err error
for k, v := range m {
switch v := v.(type) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extract method for handling interface{} and call in both convertMapNumbers and convertSliceNumbers?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

meh

@liggitt liggitt changed the title UPSTREAM: WIP: Preserve numbers in UnstructuredJSONScheme UPSTREAM: 16964: Preserve numbers in UnstructuredJSONScheme Nov 7, 2015
@liggitt
Copy link
Contributor Author

liggitt commented Nov 7, 2015

[test]

@liggitt liggitt changed the title UPSTREAM: 16964: Preserve numbers in UnstructuredJSONScheme UPSTREAM: 16964: Preserve int64 data when unmarshaling Nov 7, 2015
@liggitt
Copy link
Contributor Author

liggitt commented Nov 7, 2015

@smarterclayton @pmorie @pweil- PTAL. I think you will be pleasantly surprised at how contained the changes to unstructured.go and patch.go are

@openshift-bot
Copy link
Contributor

Evaluated for origin test up to 2ed17a9

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/test SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pull_requests_origin/6982/)


// Unmarshal unmarshals the given data
// If v is a *map[string]interface{}, numbers are converted to int64 or float64
func Unmarshal(data []byte, v interface{}) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ok for the unstructured path, but we should note this path is much slower than structured decoding. Don't want someone to switch to this path without knowing the trade off (lots more allocations).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when you do structured decoding, json looks at the types of the destination fields, so you don't have the float issue

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what I mean - I don't want someone switching to this accidentally

On Nov 7, 2015, at 9:56 AM, Jordan Liggitt [email protected] wrote:

In Godeps/_workspace/src/k8s.io/kubernetes/pkg/util/json/json.go
#5774 (comment):

+package json
+
+import (

  • "bytes"
  • "encoding/json"
    +)
    +
    +// Marshal delegates to json.Marshal
    +// It is only here so this package can be a drop-in for common encoding/json uses
    +func Marshal(v interface{}) ([]byte, error) {
  • return json.Marshal(v)
    +}
    +
    +// Unmarshal unmarshals the given data
    +// If v is a *map[string]interface{}, numbers are converted to int64 or float64
    +func Unmarshal(data []byte, v interface{}) error {

when you do structured decoding, json looks at the types of the destination
fields, so you don't have the float issue


Reply to this email directly or view it on GitHub
https://github.com/openshift/origin/pull/5774/files#r44213680.

@smarterclayton
Copy link
Contributor

Excellent patch, good tests. One request for a comment on the method that you can do upstream.

@smarterclayton smarterclayton added priority/P1 approved Indicates a PR has been approved by an approver from all required OWNERS files. area/reliability labels Nov 7, 2015
@smarterclayton
Copy link
Contributor

P1 and approved because this can result in wedged servers. [merge] and LGTM

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/merge SUCCESS (https://ci.openshift.redhat.com/jenkins/job/merge_pull_requests_origin/3962/) (Image: devenv-rhel7_2656)

@openshift-bot
Copy link
Contributor

Evaluated for origin merge up to 2ed17a9

openshift-bot pushed a commit that referenced this pull request Nov 7, 2015
@openshift-bot openshift-bot merged commit 058ba55 into openshift:master Nov 7, 2015
@liggitt liggitt deleted the json_decode branch November 7, 2015 18:52
@bparees bparees assigned bparees and unassigned bparees Feb 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/reliability priority/P1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants