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

bug #32

Open
wumingcheng opened this issue Aug 8, 2018 · 1 comment
Open

bug #32

wumingcheng opened this issue Aug 8, 2018 · 1 comment

Comments

@wumingcheng
Copy link

I found a bug, when I test jsonToyaml. when value is a number, yaml.JSONToYAML() function will return "".

func Test_JsonToYaml(t *testing.T) {
var data = { "deployment": { "kind": "Deployment", "apiVersion": "extensions/v1beta1", "metadata": { "name": "app-0807-002", "annotations": { "cpu": "0.5", "memory": "256" }, "namespace": "030bb124aef6409daec0d026f21e8dea", "labels": { "app": "app-0807-002", "ns": "030bb124aef6409daec0d026f21e8dea" } }, "spec": { "replicas": 1, "selector": { "matchLabels": { "app": "app-0807-002", "ns": "030bb124aef6409daec0d026f21e8dea" } }, "template": { "metadata": { "labels": { "app": "app-0807-002", "ns": "030bb124aef6409daec0d026f21e8dea" } }, "spec": { "containers": [ { "image": "registry.paas/library/nginx:latest", "imagePullPolicy": "IfNotPresent", "name": "nginx", "resources": { "limits": { "cpu": "500m", "memory": "256Mi" } } } ] } } } } }
yaml, err := yaml.JSONToYAML([]byte(data))
if err != nil {
fmt.Printf("err: %v\n", err)
return
}
fmt.Println(string(yaml))
}

response:
deployment:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
cpu: "0.5"
memory: "256"

labels:
app: app-0807-002
ns: 030bb124aef6409daec0d026f21e8dea
name: app-0807-002
namespace: 030bb124aef6409daec0d026f21e8dea
spec:
replicas: 1
selector:
matchLabels:
app: app-0807-002
ns: 030bb124aef6409daec0d026f21e8dea
template:
metadata:
labels:
app: app-0807-002
ns: 030bb124aef6409daec0d026f21e8dea
spec:
containers:
- image: registry.paas/library/nginx:latest
imagePullPolicy: IfNotPresent
name: nginx
resources:
limits:
cpu: 500m
memory: 256Mi

@ghostsquad
Copy link

are you saying that the cpu and memory strings in orginal json are now empty in yaml?

dims pushed a commit to dims/yaml that referenced this issue Feb 4, 2020
upgrade gopkg.in/yaml.v2 to v2.2.8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants