@@ -72,11 +72,11 @@ func GetPathContext(root any, path util.Path, createMissing bool) (*PathContext,
72
72
}
73
73
74
74
// 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 {
76
76
//scope.Debugf("WritePathContext PathContext=%s, value=%v", nc, value)
77
77
78
78
if ! util .IsValueNil (value ) {
79
- return setPathContext (nc , value , merge )
79
+ return setPathContext (nc , value , merge , tryUnmarshal )
80
80
}
81
81
82
82
//scope.Debug("delete")
@@ -107,7 +107,7 @@ func WriteNode(root any, path util.Path, value any) error {
107
107
if err != nil {
108
108
return err
109
109
}
110
- return WritePathContext (pc , value , false )
110
+ return WritePathContext (pc , value , false , true )
111
111
}
112
112
113
113
// 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 {
116
116
if err != nil {
117
117
return err
118
118
}
119
- return WritePathContext (pc , value , true )
119
+ return WritePathContext (pc , value , true , true )
120
120
}
121
121
122
122
// 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) {
137
137
if err != nil {
138
138
return false , err
139
139
}
140
- return true , WritePathContext (pc , nil , false )
140
+ return true , WritePathContext (pc , nil , false , true )
141
141
}
142
142
143
143
// getPathContext is the internal implementation of GetPathContext.
@@ -317,8 +317,8 @@ func getPathContext(nc *PathContext, fullPath, remainPath util.Path, createMissi
317
317
318
318
// setPathContext writes the given value to the Node in the given PathContext,
319
319
// 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 )
322
322
if err != nil || ! processParent {
323
323
return err
324
324
}
@@ -327,17 +327,20 @@ func setPathContext(nc *PathContext, value any, merge bool) error {
327
327
if nc .Parent .Parent == nil {
328
328
return nil
329
329
}
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
331
331
}
332
332
333
333
// setValueContext writes the given value to the Node in the given PathContext.
334
334
// 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 ) {
336
336
if nc .Parent == nil {
337
337
return false , nil
338
338
}
339
339
340
- vv , mapFromString := tryToUnmarshalStringToYAML (value )
340
+ vv , mapFromString := value , false
341
+ if tryUnmarshal {
342
+ vv , mapFromString = tryToUnmarshalStringToYAML (value )
343
+ }
341
344
342
345
switch parentNode := nc .Parent .Node .(type ) {
343
346
case * any :
0 commit comments