mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 00:52:55 +00:00
Add RNode fromMap method.
This commit is contained in:
@@ -318,8 +318,7 @@ func (rn *RNode) PipeE(functions ...Filter) error {
|
||||
return errors.Wrap(err)
|
||||
}
|
||||
|
||||
// Document returns the Node RNode for the value. Does not unwrap the node if it is a
|
||||
// DocumentNodes
|
||||
// Document returns the Node for the value.
|
||||
func (rn *RNode) Document() *yaml.Node {
|
||||
return rn.value
|
||||
}
|
||||
@@ -565,6 +564,7 @@ func (rn *RNode) GetAssociativeKey() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// MarshalJSON creates a byte slice from the RNode.
|
||||
func (rn *RNode) MarshalJSON() ([]byte, error) {
|
||||
s, err := rn.String()
|
||||
if err != nil {
|
||||
@@ -586,18 +586,13 @@ func (rn *RNode) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(m)
|
||||
}
|
||||
|
||||
// UnmarshalJSON overwrites this RNode with data from []byte.
|
||||
func (rn *RNode) UnmarshalJSON(b []byte) error {
|
||||
m := map[string]interface{}{}
|
||||
if err := json.Unmarshal(b, &m); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c, err := Marshal(m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
r, err := Parse(string(c))
|
||||
r, err := FromMap(m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -605,6 +600,14 @@ func (rn *RNode) UnmarshalJSON(b []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func FromMap(m map[string]interface{}) (*RNode, error) {
|
||||
c, err := Marshal(m)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return Parse(string(c))
|
||||
}
|
||||
|
||||
// ConvertJSONToYamlNode parses input json string and returns equivalent yaml node
|
||||
func ConvertJSONToYamlNode(jsonStr string) (*RNode, error) {
|
||||
var body map[string]interface{}
|
||||
|
||||
Reference in New Issue
Block a user