mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 17:12:51 +00:00
Implement json marshal / unmarshal so it can be used by PatchJson6902Transformer
This commit is contained in:
@@ -5,6 +5,7 @@ package yaml
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
@@ -681,6 +682,29 @@ func (rn *RNode) GetAssociativeKey() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (rn *RNode) MarshalJSON() ([]byte, error) {
|
||||
s, err := rn.String()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
m := map[string]interface{}{}
|
||||
if err := Unmarshal([]byte(s), &m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return json.Marshal(m)
|
||||
}
|
||||
|
||||
func (rn *RNode) UnmarshalJSON(b []byte) error {
|
||||
r, err := Parse(string(b))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
rn.value = r.value
|
||||
return nil
|
||||
}
|
||||
|
||||
// checkKey returns true if all elems have the key
|
||||
func checkKey(key string, elems []*Node) bool {
|
||||
count := 0
|
||||
|
||||
Reference in New Issue
Block a user