@@ -72,11 +72,11 @@ func GetPathContext(root any, path util.Path, createMissing bool) (*PathContext,
7272}
7373
7474// WritePathContext writes the given value to the Node in the given PathContext.
75- func WritePathContext (nc * PathContext , value any , merge bool ) error {
75+ func WritePathContext (nc * PathContext , value any , merge bool , tryUnmarshal bool ) error {
7676 //scope.Debugf("WritePathContext PathContext=%s, value=%v", nc, value)
7777
7878 if ! util .IsValueNil (value ) {
79- return setPathContext (nc , value , merge )
79+ return setPathContext (nc , value , merge , tryUnmarshal )
8080 }
8181
8282 //scope.Debug("delete")
@@ -107,7 +107,7 @@ func WriteNode(root any, path util.Path, value any) error {
107107 if err != nil {
108108 return err
109109 }
110- return WritePathContext (pc , value , false )
110+ return WritePathContext (pc , value , false , true )
111111}
112112
113113// MergeNode merges value to the tree in root at the given path, creating any required missing internal nodes in path.
@@ -116,7 +116,7 @@ func MergeNode(root any, path util.Path, value any) error {
116116 if err != nil {
117117 return err
118118 }
119- return WritePathContext (pc , value , true )
119+ return WritePathContext (pc , value , true , true )
120120}
121121
122122// Find returns the value at path from the given tree, or false if the path does not exist.
@@ -137,7 +137,7 @@ func Delete(root map[string]any, path util.Path) (bool, error) {
137137 if err != nil {
138138 return false , err
139139 }
140- return true , WritePathContext (pc , nil , false )
140+ return true , WritePathContext (pc , nil , false , true )
141141}
142142
143143// getPathContext is the internal implementation of GetPathContext.
@@ -317,8 +317,8 @@ func getPathContext(nc *PathContext, fullPath, remainPath util.Path, createMissi
317317
318318// setPathContext writes the given value to the Node in the given PathContext,
319319// enlarging all PathContext lists to ensure all indexes are valid.
320- func setPathContext (nc * PathContext , value any , merge bool ) error {
321- processParent , err := setValueContext (nc , value , merge )
320+ func setPathContext (nc * PathContext , value any , merge bool , tryUnmarshal bool ) error {
321+ processParent , err := setValueContext (nc , value , merge , tryUnmarshal )
322322 if err != nil || ! processParent {
323323 return err
324324 }
@@ -327,17 +327,20 @@ func setPathContext(nc *PathContext, value any, merge bool) error {
327327 if nc .Parent .Parent == nil {
328328 return nil
329329 }
330- return setPathContext (nc .Parent , nc .Parent .Node , false ) // note: tail recursive
330+ return setPathContext (nc .Parent , nc .Parent .Node , false , tryUnmarshal ) // note: tail recursive
331331}
332332
333333// setValueContext writes the given value to the Node in the given PathContext.
334334// If setting the value requires growing the final slice, grows it.
335- func setValueContext (nc * PathContext , value any , merge bool ) (bool , error ) {
335+ func setValueContext (nc * PathContext , value any , merge bool , tryUnmarshal bool ) (bool , error ) {
336336 if nc .Parent == nil {
337337 return false , nil
338338 }
339339
340- vv , mapFromString := tryToUnmarshalStringToYAML (value )
340+ vv , mapFromString := value , false
341+ if tryUnmarshal {
342+ vv , mapFromString = tryToUnmarshalStringToYAML (value )
343+ }
341344
342345 switch parentNode := nc .Parent .Node .(type ) {
343346 case * any :
0 commit comments